Skip to content

Commit 69673bc

Browse files
committed
Review nullability of spring-ws-security
See gh-1562
1 parent 16dd68a commit 69673bc

29 files changed

+140
-68
lines changed

spring-ws-security/src/main/java/org/springframework/ws/soap/security/AbstractWsSecurityInterceptor.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
import java.util.Iterator;
2020
import java.util.Locale;
21+
import java.util.Objects;
2122

2223
import javax.xml.namespace.QName;
2324

2425
import org.apache.commons.logging.Log;
2526
import org.apache.commons.logging.LogFactory;
27+
import org.jspecify.annotations.Nullable;
2628

2729
import org.springframework.util.Assert;
2830
import org.springframework.ws.client.WebServiceClientException;
@@ -69,7 +71,7 @@ public abstract class AbstractWsSecurityInterceptor implements SoapEndpointInter
6971

7072
private boolean skipValidationIfNoHeaderPresent = false;
7173

72-
private EndpointExceptionResolver exceptionResolver;
74+
private @Nullable EndpointExceptionResolver exceptionResolver;
7375

7476
/**
7577
* Indicates whether server-side incoming request are to be validated. Defaults to
@@ -197,7 +199,7 @@ public boolean handleFault(MessageContext messageContext, Object endpoint) throw
197199
}
198200

199201
@Override
200-
public void afterCompletion(MessageContext messageContext, Object endpoint, Exception ex) {
202+
public void afterCompletion(MessageContext messageContext, Object endpoint, @Nullable Exception ex) {
201203
cleanUp();
202204
}
203205

@@ -279,7 +281,8 @@ public boolean handleFault(MessageContext messageContext) throws WebServiceClien
279281
}
280282

281283
@Override
282-
public void afterCompletion(MessageContext messageContext, Exception ex) throws WebServiceClientException {
284+
public void afterCompletion(MessageContext messageContext, @Nullable Exception ex)
285+
throws WebServiceClientException {
283286
cleanUp();
284287
}
285288

@@ -320,7 +323,7 @@ protected boolean handleValidationException(WsSecurityValidationException ex, Me
320323
this.logger.debug("No exception resolver present, creating basic soap fault");
321324
}
322325
SoapBody response = ((SoapMessage) messageContext.getResponse()).getSoapBody();
323-
response.addClientOrSenderFault(ex.getMessage(), Locale.ENGLISH);
326+
response.addClientOrSenderFault(Objects.requireNonNull(ex.getMessage()), Locale.ENGLISH);
324327
}
325328
return false;
326329
}

spring-ws-security/src/main/java/org/springframework/ws/soap/security/WsSecurityException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.ws.soap.security;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.ws.WebServiceException;
2022

2123
/**
@@ -32,7 +34,7 @@ public WsSecurityException(String msg) {
3234
super(msg);
3335
}
3436

35-
public WsSecurityException(String msg, Throwable ex) {
37+
public WsSecurityException(@Nullable String msg, Throwable ex) {
3638
super(msg, ex);
3739
}
3840

spring-ws-security/src/main/java/org/springframework/ws/soap/security/WsSecuritySecurementException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.ws.soap.security;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
/**
2022
* Exception indicating that something went wrong during the securement of a message.
2123
* <p>
@@ -33,7 +35,7 @@ public WsSecuritySecurementException(String msg) {
3335
super(msg);
3436
}
3537

36-
public WsSecuritySecurementException(String msg, Throwable ex) {
38+
public WsSecuritySecurementException(@Nullable String msg, Throwable ex) {
3739
super(msg, ex);
3840
}
3941

spring-ws-security/src/main/java/org/springframework/ws/soap/security/WsSecurityValidationException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.ws.soap.security;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
/**
2022
* Exception indicating that something went wrong during the validation of a message.
2123
* <p>
@@ -33,7 +35,7 @@ public WsSecurityValidationException(String msg) {
3335
super(msg);
3436
}
3537

36-
public WsSecurityValidationException(String msg, Throwable ex) {
38+
public WsSecurityValidationException(@Nullable String msg, Throwable ex) {
3739
super(msg, ex);
3840
}
3941

spring-ws-security/src/main/java/org/springframework/ws/soap/security/callback/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Contains generic {@code CallbackHandler} implementations.
1919
*/
20+
@NullMarked
2021
package org.springframework.ws.soap.security.callback;
22+
23+
import org.jspecify.annotations.NullMarked;

spring-ws-security/src/main/java/org/springframework/ws/soap/security/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@
1818
* Provides WS-Security implementation classes. Contains the
1919
* {@code AbstractWsSecurityInterceptor} and exceptions.
2020
*/
21+
@NullMarked
2122
package org.springframework.ws.soap.security;
23+
24+
import org.jspecify.annotations.NullMarked;

spring-ws-security/src/main/java/org/springframework/ws/soap/security/support/KeyManagersFactoryBean.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import javax.net.ssl.KeyManager;
2222
import javax.net.ssl.KeyManagerFactory;
2323

24+
import org.jspecify.annotations.Nullable;
25+
2426
import org.springframework.beans.factory.FactoryBean;
2527
import org.springframework.beans.factory.InitializingBean;
2628
import org.springframework.util.StringUtils;
@@ -38,21 +40,21 @@
3840
*/
3941
public class KeyManagersFactoryBean implements FactoryBean<KeyManager[]>, InitializingBean {
4042

41-
private KeyManager[] keyManagers;
43+
private KeyManager @Nullable [] keyManagers;
4244

43-
private KeyStore keyStore;
45+
private @Nullable KeyStore keyStore;
4446

45-
private String algorithm;
47+
private @Nullable String algorithm;
4648

47-
private String provider;
49+
private @Nullable String provider;
4850

49-
private char[] password;
51+
private char @Nullable [] password;
5052

5153
/**
5254
* Sets the password to use for integrity checking. If this property is not set, then
5355
* integrity checking is not performed.
5456
*/
55-
public void setPassword(String password) {
57+
public void setPassword(@Nullable String password) {
5658
if (password != null) {
5759
this.password = password.toCharArray();
5860
}
@@ -84,7 +86,7 @@ public void setKeyStore(KeyStore keyStore) {
8486
}
8587

8688
@Override
87-
public KeyManager[] getObject() throws Exception {
89+
public KeyManager @Nullable [] getObject() throws Exception {
8890
return this.keyManagers;
8991
}
9092

spring-ws-security/src/main/java/org/springframework/ws/soap/security/support/KeyStoreFactoryBean.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323

2424
import org.apache.commons.logging.Log;
2525
import org.apache.commons.logging.LogFactory;
26+
import org.jspecify.annotations.Nullable;
2627

2728
import org.springframework.beans.factory.FactoryBean;
2829
import org.springframework.beans.factory.InitializingBean;
2930
import org.springframework.core.io.Resource;
31+
import org.springframework.util.Assert;
3032
import org.springframework.util.StringUtils;
3133

3234
/**
@@ -45,30 +47,30 @@ public class KeyStoreFactoryBean implements FactoryBean<KeyStore>, InitializingB
4547

4648
private static final Log logger = LogFactory.getLog(KeyStoreFactoryBean.class);
4749

48-
private KeyStore keyStore;
50+
private @Nullable KeyStore keyStore;
4951

50-
private String type;
52+
private @Nullable String type;
5153

52-
private String provider;
54+
private @Nullable String provider;
5355

54-
private Resource location;
56+
private @Nullable Resource location;
5557

56-
private char[] password;
58+
private char @Nullable [] password;
5759

5860
/**
5961
* Sets the location of the key store to use. If this is not set, a new, empty key
6062
* store will be used.
6163
* @see KeyStore#load(java.io.InputStream,char[])
6264
*/
63-
public void setLocation(Resource location) {
65+
public void setLocation(@Nullable Resource location) {
6466
this.location = location;
6567
}
6668

6769
/**
6870
* Sets the password to use for integrity checking. If this property is not set, then
6971
* integrity checking is not performed.
7072
*/
71-
public void setPassword(String password) {
73+
public void setPassword(@Nullable String password) {
7274
if (password != null) {
7375
this.password = password.toCharArray();
7476
}
@@ -86,12 +88,13 @@ public void setProvider(String provider) {
8688
* used.
8789
* @see KeyStore#getDefaultType()
8890
*/
89-
public void setType(String type) {
91+
public void setType(@Nullable String type) {
9092
this.type = type;
9193
}
9294

9395
@Override
9496
public KeyStore getObject() {
97+
Assert.state(this.keyStore != null, "KeyStore has not been initialized");
9598
return this.keyStore;
9699
}
97100

spring-ws-security/src/main/java/org/springframework/ws/soap/security/support/TrustManagersFactoryBean.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import javax.net.ssl.TrustManager;
2222
import javax.net.ssl.TrustManagerFactory;
2323

24+
import org.jspecify.annotations.Nullable;
25+
2426
import org.springframework.beans.factory.FactoryBean;
2527
import org.springframework.beans.factory.InitializingBean;
2628
import org.springframework.util.StringUtils;
@@ -37,13 +39,13 @@
3739
*/
3840
public class TrustManagersFactoryBean implements FactoryBean<TrustManager[]>, InitializingBean {
3941

40-
private TrustManager[] trustManagers;
42+
private TrustManager @Nullable [] trustManagers;
4143

42-
private KeyStore keyStore;
44+
private @Nullable KeyStore keyStore;
4345

44-
private String algorithm;
46+
private @Nullable String algorithm;
4547

46-
private String provider;
48+
private @Nullable String provider;
4749

4850
/**
4951
* Sets the provider of the trust manager to use. If this is not set, the default is
@@ -71,7 +73,7 @@ public void setKeyStore(KeyStore keyStore) {
7173
}
7274

7375
@Override
74-
public TrustManager[] getObject() throws Exception {
76+
public TrustManager @Nullable [] getObject() throws Exception {
7577
return this.trustManagers;
7678
}
7779

spring-ws-security/src/main/java/org/springframework/ws/soap/security/support/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Contains support classes for handling WS-Security messages.
1919
*/
20+
@NullMarked
2021
package org.springframework.ws.soap.security.support;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)