Skip to content

Commit 10a405b

Browse files
committed
refactor: replace NullPointerException with more suitable IllegalArgumentException
WE2-1030 Signed-off-by: Sven Mitt <svenzik@users.noreply.github.com>
1 parent 310224e commit 10a405b

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

src/main/java/eu/webeid/security/certificate/CertificateValidator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public static void requireCertificateIsValidOnDate(X509Certificate cert, Date da
102102
* {@link RevocationMode#CUSTOM_PKIX} when the provided {@code customPkixRevocationChecker}
103103
* has an explicit OCSP responder URI configured; otherwise it is empty.
104104
* <p>
105-
* @throws NullPointerException if any required parameter is {@code null}
106105
* @throws IllegalArgumentException if the supplied checker parameters are inconsistent with {@code revocationMode}
107106
* @throws CertificateNotYetValidException if the subject or trust anchor certificate is not yet valid at {@code now}
108107
* @throws CertificateExpiredException if the subject or trust anchor certificate is expired at {@code now}

src/main/java/eu/webeid/security/validator/AuthTokenValidationConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.security.cert.X509Certificate;
3535
import java.util.Collection;
3636
import java.util.HashSet;
37-
import java.util.Objects;
3837
import java.util.Set;
3938

4039
/**
@@ -116,11 +115,9 @@ public RevocationMode getRevocationMode() {
116115
/**
117116
* Checks that the configuration parameters are valid.
118117
*
119-
* @throws NullPointerException when required parameters are null
120118
* @throws IllegalArgumentException when any parameter is invalid
121119
*/
122120
void validate() {
123-
Objects.requireNonNull(siteOrigin, "Origin URI must not be null");
124121
validateIsOriginURL(siteOrigin);
125122
if (trustedCACertificates.isEmpty()) {
126123
throw new IllegalArgumentException("At least one trusted certificate authority must be provided");
@@ -141,6 +138,9 @@ AuthTokenValidationConfiguration copy() {
141138
*/
142139
public static void validateIsOriginURL(URI uri) throws IllegalArgumentException {
143140
try {
141+
if (uri == null) {
142+
throw new IllegalArgumentException("Origin URI must not be null");
143+
}
144144
// 1. Verify that the URI can be converted to absolute URL.
145145
uri.toURL();
146146
// 2. Verify that the URI contains only HTTPS scheme, host and optional port components.

src/main/java/eu/webeid/security/validator/AuthTokenValidatorBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,10 @@ public AuthTokenValidatorBuilder withPKIXRevocationChecker(PKIXRevocationChecker
146146
* The returned {@link AuthTokenValidator} object is immutable/thread-safe.
147147
*
148148
* @return the configured authentication token validator object
149-
* @throws NullPointerException when required parameters are null
150149
* @throws IllegalArgumentException when any parameter is invalid
151-
* @throws RuntimeException when JCE configuration is invalid
150+
* @throws JceException when JCE configuration is invalid
152151
*/
153-
public AuthTokenValidator build() throws NullPointerException, IllegalArgumentException, JceException {
152+
public AuthTokenValidator build() throws IllegalArgumentException, JceException {
154153
configuration.validate();
155154
return new AuthTokenValidatorImpl(configuration);
156155
}

src/test/java/eu/webeid/security/validator/AuthTokenValidatorBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class AuthTokenValidatorBuilderTest {
4444
@Test
4545
void testOriginMissing() {
4646
assertThatThrownBy(builder::build)
47-
.isInstanceOf(NullPointerException.class)
47+
.isInstanceOf(IllegalArgumentException.class)
4848
.hasMessageStartingWith("Origin URI must not be null");
4949
}
5050

0 commit comments

Comments
 (0)