Skip to content

Commit cb4df25

Browse files
committed
Switched from MiscUtil.checkNotNull to Objects.requireNotNull
1 parent a240e5c commit cb4df25

File tree

8 files changed

+24
-44
lines changed

8 files changed

+24
-44
lines changed

modules/authenticated-socks-module/src/main/java/org/simplejavamail/internal/authenticatedsockssupport/socks5client/KeyStoreInfo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.simplejavamail.internal.authenticatedsockssupport.socks5client;
22

3-
import org.simplejavamail.internal.util.MiscUtil;
3+
import static java.util.Objects.requireNonNull;
44

55
@SuppressWarnings("SameParameterValue")
66
class KeyStoreInfo {
@@ -18,9 +18,9 @@ public KeyStoreInfo(final String keyStorePath, final String password) {
1818
}
1919

2020
public KeyStoreInfo(final String keyStorePath, final String password, final String type) {
21-
this.keyStorePath = MiscUtil.checkNotNull(keyStorePath, "Argument [keyStorePath] may not be null");
22-
this.password = MiscUtil.checkNotNull(password, "Argument [password] may not be null");
23-
this.type = MiscUtil.checkNotNull(type, "Argument [type] may not be null");
21+
this.keyStorePath = requireNonNull(keyStorePath, "Argument [keyStorePath] may not be null");
22+
this.password = requireNonNull(password, "Argument [password] may not be null");
23+
this.type = requireNonNull(type, "Argument [type] may not be null");
2424
}
2525

2626
public String getKeyStorePath() {

modules/authenticated-socks-module/src/main/java/org/simplejavamail/internal/authenticatedsockssupport/socks5client/ProxyCredentials.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.simplejavamail.internal.authenticatedsockssupport.socks5client;
22

3-
import org.simplejavamail.internal.util.MiscUtil;
3+
import static java.util.Objects.requireNonNull;
44

55
public class ProxyCredentials {
66

@@ -13,7 +13,7 @@ public ProxyCredentials() {
1313

1414
public ProxyCredentials(final String username, final String password) {
1515
this.username = username;
16-
this.password = MiscUtil.checkNotNull(password, "Argument [password] may not be null");
16+
this.password = requireNonNull(password, "Argument [password] may not be null");
1717
}
1818

1919
public String getUsername() {

modules/authenticated-socks-module/src/main/java/org/simplejavamail/internal/authenticatedsockssupport/socks5client/SSLConfiguration.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.simplejavamail.internal.authenticatedsockssupport.socks5client;
22

33
import org.simplejavamail.internal.authenticatedsockssupport.common.SocksException;
4-
import org.simplejavamail.internal.util.MiscUtil;
54
import org.slf4j.Logger;
65
import org.slf4j.LoggerFactory;
76

@@ -18,6 +17,8 @@
1817
import java.security.UnrecoverableKeyException;
1918
import java.security.cert.CertificateException;
2019

20+
import static java.util.Objects.requireNonNull;
21+
2122
class SSLConfiguration {
2223

2324
private static final Logger LOGGER = LoggerFactory.getLogger(SSLConfiguration.class);
@@ -33,8 +34,8 @@ private SSLConfiguration(final KeyStoreInfo keyStoreInfo, final KeyStoreInfo tru
3334

3435
public SSLSocketFactory getSSLSocketFactory()
3536
throws SocksException {
36-
MiscUtil.checkNotNull(trustKeyStoreInfo, "trustKeyStoreInfo may not be null");
37-
FileInputStream s1 = null;
37+
requireNonNull(trustKeyStoreInfo, "trustKeyStoreInfo may not be null");
38+
FileInputStream s1 = null;
3839
FileInputStream s2 = null;
3940
try {
4041
final SSLContext context = SSLContext.getInstance("SSL");

modules/authenticated-socks-module/src/main/java/org/simplejavamail/internal/authenticatedsockssupport/socks5client/SocksAuthenticationHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.net.Socket;
1212

1313
import static java.nio.charset.StandardCharsets.UTF_8;
14+
import static java.util.Objects.requireNonNull;
1415

1516
final class SocksAuthenticationHelper {
1617
private static final Logger LOGGER = LoggerFactory.getLogger(SocksAuthenticationHelper.class);
@@ -56,8 +57,8 @@ public static boolean shouldAuthenticate(final Socket socket)
5657

5758
public static void performUserPasswordAuthentication(final Socks5 socksProxy)
5859
throws IOException {
59-
MiscUtil.checkNotNull(socksProxy, "Argument [socksProxy] may not be null");
60-
final ProxyCredentials credentials = socksProxy.getCredentials();
60+
requireNonNull(socksProxy, "Argument [socksProxy] may not be null");
61+
final ProxyCredentials credentials = socksProxy.getCredentials();
6162
if (credentials == null) {
6263
throw new SocksException("Need Username/Password authentication");
6364
}

modules/authenticated-socks-module/src/main/java/org/simplejavamail/internal/authenticatedsockssupport/socks5client/SocksSocket.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.jetbrains.annotations.NotNull;
44
import org.simplejavamail.internal.authenticatedsockssupport.common.SocksException;
5-
import org.simplejavamail.internal.util.MiscUtil;
65
import org.slf4j.Logger;
76
import org.slf4j.LoggerFactory;
87

@@ -35,9 +34,9 @@ public class SocksSocket extends Socket {
3534

3635
private SocksSocket(final Socks5 proxy, final String remoteServerHost, final int remoteServerPort)
3736
throws IOException {
38-
this.proxy = MiscUtil.checkNotNull(proxy, "Argument [proxy] may not be null").copy();
37+
this.proxy = requireNonNull(proxy, "Argument [proxy] may not be null").copy();
3938
this.proxy.setProxySocket(proxySocket);
40-
this.remoteServerHost = MiscUtil.checkNotNull(remoteServerHost, "Argument [remoteServerHost] may not be null");
39+
this.remoteServerHost = requireNonNull(remoteServerHost, "Argument [remoteServerHost] may not be null");
4140
this.remoteServerPort = remoteServerPort;
4241
this.proxy.buildConnection();
4342
proxySocket = this.proxy.getProxySocket();
@@ -52,9 +51,9 @@ private SocksSocket(final Socks5 proxy, final InetAddress address, final int por
5251

5352
public SocksSocket(final Socks5 proxy, final InetSocketAddress socketAddress)
5453
throws IOException {
55-
MiscUtil.checkNotNull(proxy, "Argument [proxy] may not be null");
56-
MiscUtil.checkNotNull(socketAddress, "Argument [socketAddress] may not be null");
57-
this.proxy = proxy.copy();
54+
requireNonNull(proxy, "Argument [proxy] may not be null");
55+
requireNonNull(socketAddress, "Argument [socketAddress] may not be null");
56+
this.proxy = proxy.copy();
5857
this.remoteServerHost = socketAddress.getHostString();
5958
this.remoteServerPort = socketAddress.getPort();
6059
this.proxy.buildConnection();
@@ -77,9 +76,9 @@ public SocksSocket(final Socks5 proxy, final Socket proxySocket, final InetSocke
7776

7877
@SuppressWarnings("WeakerAccess")
7978
public SocksSocket(final Socks5 proxy, final Socket proxySocket) {
80-
MiscUtil.checkNotNull(proxy, "Argument [proxy] may not be null");
81-
MiscUtil.checkNotNull(proxySocket, "Argument [proxySocket] may not be null");
82-
if (proxySocket.isConnected()) {
79+
requireNonNull(proxy, "Argument [proxy] may not be null");
80+
requireNonNull(proxySocket, "Argument [proxySocket] may not be null");
81+
if (proxySocket.isConnected()) {
8382
throw new IllegalArgumentException("Proxy socket should be unconnected");
8483
}
8584
this.proxySocket = proxySocket;

modules/core-module/src/main/java/org/simplejavamail/internal/util/MiscUtil.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.simplejavamail.internal.util;
22

3-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
43
import jakarta.activation.DataSource;
54
import jakarta.activation.FileDataSource;
65
import jakarta.activation.URLDataSource;
@@ -52,14 +51,6 @@ public final class MiscUtil {
5251

5352
private static final Random RANDOM = new Random();
5453

55-
@SuppressFBWarnings(value = "NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE")
56-
public static <T> T checkNotNull(final @Nullable T value, final @Nullable String msg) {
57-
if (value == null) {
58-
throw new NullPointerException(msg);
59-
}
60-
return value;
61-
}
62-
6354
public static <T> T checkArgumentNotEmpty(final @Nullable T value, final @Nullable String msg) {
6455
if (valueNullOrEmpty(value)) {
6556
throw new IllegalArgumentException(msg);

modules/simple-java-mail/src/main/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import static java.nio.charset.StandardCharsets.UTF_8;
5252
import static java.util.Arrays.asList;
5353
import static java.util.Collections.singletonList;
54+
import static java.util.Objects.requireNonNull;
5455
import static java.util.regex.Matcher.quoteReplacement;
5556
import static org.simplejavamail.config.ConfigLoader.Property.DEFAULT_BCC_ADDRESS;
5657
import static org.simplejavamail.config.ConfigLoader.Property.DEFAULT_BCC_NAME;
@@ -90,7 +91,6 @@
9091
import static org.simplejavamail.email.internal.EmailException.ERROR_RESOLVING_IMAGE_DATASOURCE;
9192
import static org.simplejavamail.email.internal.EmailException.NAME_MISSING_FOR_EMBEDDED_IMAGE;
9293
import static org.simplejavamail.internal.smimesupport.SmimeRecognitionUtil.isGeneratedSmimeMessageId;
93-
import static org.simplejavamail.internal.util.MiscUtil.checkNotNull;
9494
import static org.simplejavamail.internal.util.MiscUtil.defaultTo;
9595
import static org.simplejavamail.internal.util.MiscUtil.extractEmailAddresses;
9696
import static org.simplejavamail.internal.util.MiscUtil.randomCid10;
@@ -1735,7 +1735,7 @@ public EmailPopulatingBuilder withAttachment(@Nullable final String name, @NotNu
17351735
*/
17361736
@Override
17371737
public EmailPopulatingBuilder withAttachment(@Nullable final String name, @NotNull final byte[] data, @NotNull final String mimetype, @Nullable final String description, @Nullable final ContentTransferEncoding contentTransferEncoding) {
1738-
checkNotNull(data, "data");
1738+
requireNonNull(data, "data");
17391739
checkNonEmptyArgument(mimetype, "mimetype");
17401740
final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
17411741
dataSource.setName(name);

modules/simple-java-mail/src/test/java/org/simplejavamail/internal/util/MiscUtilTest.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,7 @@
1717
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1818

1919
public class MiscUtilTest {
20-
@Test
21-
@SuppressWarnings("ObviousNullCheck")
22-
public void checkNotNull() {
23-
assertThat(MiscUtil.checkNotNull("", null)).isEqualTo("");
24-
assertThat(MiscUtil.checkNotNull("blah", null)).isEqualTo("blah");
25-
assertThat(MiscUtil.checkNotNull(23523, null)).isEqualTo(23523);
26-
}
27-
28-
@Test(expected = NullPointerException.class)
29-
public void checkNotNullWithException() {
30-
MiscUtil.checkNotNull(null, null);
31-
}
32-
20+
3321
@Test
3422
public void checkArgumentNotEmpty() {
3523
assertThat(MiscUtil.checkArgumentNotEmpty("blah", null)).isEqualTo("blah");

0 commit comments

Comments
 (0)