Skip to content

Commit e1dc6f5

Browse files
committed
Add nullability support
This reviews the entire code base to explicitly declare APIs that accept and/or return a null value. The code base is validated using ErrorProne. Closes gh-1562
2 parents d370dbd + 06eaa1d commit e1dc6f5

File tree

358 files changed

+1895
-1097
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

358 files changed

+1895
-1097
lines changed

gradle/plugins/conventions-plugin/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies {
1515
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:${javaFormatVersion}")
1616

1717
implementation("com.github.ben-manes:gradle-versions-plugin:$gradleVersionsPluginVersion")
18+
implementation("io.spring.gradle.nullability:nullability-plugin:$nullabilityPluginVersion")
1819
implementation("io.spring.javaformat:spring-javaformat-gradle-plugin:$javaFormatVersion")
1920

2021
testImplementation("org.junit.jupiter:junit-jupiter")

gradle/plugins/conventions-plugin/src/main/java/org/springframework/ws/gradle/conventions/ConventionsPlugin.java

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

1717
package org.springframework.ws.gradle.conventions;
1818

19+
import io.spring.gradle.nullability.NullabilityPlugin;
1920
import org.gradle.api.Plugin;
2021
import org.gradle.api.Project;
2122
import org.gradle.api.plugins.JavaBasePlugin;
@@ -37,7 +38,10 @@ public void apply(Project project) {
3738
new JavaBasePluginConventions().apply(project);
3839
new CheckstyleConventions().apply(project);
3940
});
40-
project.getPlugins().withType(JavaPlugin.class).all((plugin) -> new JavaPluginConventions().apply(project));
41+
project.getPlugins().withType(JavaPlugin.class).all((plugin) -> {
42+
project.getPlugins().apply(NullabilityPlugin.class);
43+
new JavaPluginConventions().apply(project);
44+
});
4145
project.getPlugins()
4246
.withType(MavenPublishPlugin.class)
4347
.all((plugin) -> new MavenPublishPluginConventions().apply(project));

gradle/plugins/gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
assertJVersion=3.25.3
22
gradleVersionsPluginVersion=0.52.0
3-
javaFormatVersion=0.0.45
3+
javaFormatVersion=0.0.46
44
junitVersion=5.11.0
5+
nullabilityPluginVersion=0.0.1

spring-ws-core/src/main/java/org/springframework/ws/FaultAwareWebServiceMessage.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import javax.xml.namespace.QName;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
/**
2224
* Sub-interface of {@link WebServiceMessage} that can contain special Fault messages.
2325
* Fault messages (such as {@link org.springframework.ws.soap.SoapFault} SOAP Faults)
@@ -39,14 +41,14 @@ public interface FaultAwareWebServiceMessage extends WebServiceMessage {
3941
/**
4042
* Returns the fault code, if any.
4143
*/
42-
QName getFaultCode();
44+
@Nullable QName getFaultCode();
4345

4446
/**
4547
* Returns the fault reason message.
4648
* @return the fault reason message, if any; returns {@code null} when no fault is
4749
* present.
4850
* @see #hasFault()
4951
*/
50-
String getFaultReason();
52+
@Nullable String getFaultReason();
5153

5254
}

spring-ws-core/src/main/java/org/springframework/ws/WebServiceException.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.ws;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.core.NestedRuntimeException;
2022

2123
/**
@@ -31,7 +33,7 @@ public abstract class WebServiceException extends NestedRuntimeException {
3133
* Create a new instance of the {@code WebServiceException} class.
3234
* @param msg the detail message
3335
*/
34-
public WebServiceException(String msg) {
36+
public WebServiceException(@Nullable String msg) {
3537
super(msg);
3638
}
3739

@@ -40,7 +42,7 @@ public WebServiceException(String msg) {
4042
* @param msg the detail message
4143
* @param ex the root {@link Throwable exception}
4244
*/
43-
public WebServiceException(String msg, Throwable ex) {
45+
public WebServiceException(@Nullable String msg, Throwable ex) {
4446
super(msg, ex);
4547
}
4648

spring-ws-core/src/main/java/org/springframework/ws/WebServiceMessage.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import javax.xml.transform.Result;
2323
import javax.xml.transform.Source;
2424

25+
import org.jspecify.annotations.Nullable;
26+
2527
/**
2628
* Represents a protocol-agnostic XML message.
2729
* <p>
@@ -41,7 +43,7 @@ public interface WebServiceMessage {
4143
* single time.
4244
* @return the message contents
4345
*/
44-
Source getPayloadSource();
46+
@Nullable Source getPayloadSource();
4547

4648
/**
4749
* Returns the contents of the message as a {@link Result}.

spring-ws-core/src/main/java/org/springframework/ws/client/WebServiceClientException.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.client;
1818

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

2123
/**
@@ -31,7 +33,7 @@ public abstract class WebServiceClientException extends WebServiceException {
3133
* Create a new instance of the {@code WebServiceClientException} class.
3234
* @param msg the detail message
3335
*/
34-
public WebServiceClientException(String msg) {
36+
public WebServiceClientException(@Nullable String msg) {
3537
super(msg);
3638
}
3739

spring-ws-core/src/main/java/org/springframework/ws/client/WebServiceFaultException.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.ws.client;
1818

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

2123
/**
@@ -27,7 +29,7 @@
2729
@SuppressWarnings("serial")
2830
public class WebServiceFaultException extends WebServiceClientException {
2931

30-
private final FaultAwareWebServiceMessage faultMessage;
32+
private final @Nullable FaultAwareWebServiceMessage faultMessage;
3133

3234
/** Create a new instance of the {@code WebServiceFaultException} class. */
3335
public WebServiceFaultException(String msg) {
@@ -45,7 +47,7 @@ public WebServiceFaultException(FaultAwareWebServiceMessage faultMessage) {
4547
}
4648

4749
/** Returns the fault message. */
48-
public FaultAwareWebServiceMessage getWebServiceMessage() {
50+
public @Nullable FaultAwareWebServiceMessage getWebServiceMessage() {
4951
return this.faultMessage;
5052
}
5153

spring-ws-core/src/main/java/org/springframework/ws/client/WebServiceIOException.java

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

1919
import java.io.IOException;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
/**
2224
* Exception thrown whenever an I/O error occurs on the client-side.
2325
*
@@ -31,7 +33,7 @@ public class WebServiceIOException extends WebServiceClientException {
3133
* Create a new instance of the {@code WebServiceIOException} class.
3234
* @param msg the detail message
3335
*/
34-
public WebServiceIOException(String msg) {
36+
public WebServiceIOException(@Nullable String msg) {
3537
super(msg);
3638
}
3739

spring-ws-core/src/main/java/org/springframework/ws/client/WebServiceTransportException.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.client;
1818

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

2123
/**
@@ -31,7 +33,7 @@ public class WebServiceTransportException extends WebServiceIOException {
3133
* Create a new instance of the {@code WebServiceTransportException} class.
3234
* @param msg the detail message
3335
*/
34-
public WebServiceTransportException(String msg) {
36+
public WebServiceTransportException(@Nullable String msg) {
3537
super(msg);
3638
}
3739

spring-ws-core/src/main/java/org/springframework/ws/client/core/SourceExtractor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import javax.xml.transform.Source;
2222
import javax.xml.transform.TransformerException;
2323

24+
import org.jspecify.annotations.Nullable;
25+
2426
/**
2527
* Callback interface for extracting a result object from a
2628
* {@link javax.xml.transform.Source} instance.
@@ -49,6 +51,6 @@ public interface SourceExtractor<T> {
4951
* typically be stateful in the latter case)
5052
* @throws IOException in case of I/O errors
5153
*/
52-
T extractData(Source source) throws IOException, TransformerException;
54+
@Nullable T extractData(@Nullable Source source) throws IOException, TransformerException;
5355

5456
}

spring-ws-core/src/main/java/org/springframework/ws/client/core/WebServiceMessageExtractor.java

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

2121
import javax.xml.transform.TransformerException;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.ws.WebServiceMessage;
2426

2527
/**
@@ -50,6 +52,6 @@ public interface WebServiceMessageExtractor<T> {
5052
* @throws IOException in case of I/O errors
5153
* @throws TransformerException in case of transformation errors
5254
*/
53-
T extractData(WebServiceMessage message) throws IOException, TransformerException;
55+
@Nullable T extractData(WebServiceMessage message) throws IOException, TransformerException;
5456

5557
}

spring-ws-core/src/main/java/org/springframework/ws/client/core/WebServiceOperations.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import javax.xml.transform.Result;
2020
import javax.xml.transform.Source;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.oxm.XmlMappingException;
2325
import org.springframework.ws.client.WebServiceClientException;
2426

@@ -46,8 +48,8 @@ public interface WebServiceOperations {
4648
* @throws WebServiceClientException if there is a problem sending or receiving the
4749
* message
4850
*/
49-
<T> T sendAndReceive(WebServiceMessageCallback requestCallback, WebServiceMessageExtractor<T> responseExtractor)
50-
throws WebServiceClientException;
51+
<T> @Nullable T sendAndReceive(WebServiceMessageCallback requestCallback,
52+
WebServiceMessageExtractor<T> responseExtractor) throws WebServiceClientException;
5153

5254
/**
5355
* Sends a web service message that can be manipulated with the given callback,
@@ -61,7 +63,7 @@ <T> T sendAndReceive(WebServiceMessageCallback requestCallback, WebServiceMessag
6163
* @throws WebServiceClientException if there is a problem sending or receiving the
6264
* message
6365
*/
64-
<T> T sendAndReceive(String uri, WebServiceMessageCallback requestCallback,
66+
<T> @Nullable T sendAndReceive(String uri, WebServiceMessageCallback requestCallback,
6567
WebServiceMessageExtractor<T> responseExtractor) throws WebServiceClientException;
6668

6769
/**
@@ -112,7 +114,7 @@ boolean sendAndReceive(String uri, WebServiceMessageCallback requestCallback,
112114
* @see WebServiceTemplate#setMarshaller(org.springframework.oxm.Marshaller)
113115
* @see WebServiceTemplate#setUnmarshaller(org.springframework.oxm.Unmarshaller)
114116
*/
115-
Object marshalSendAndReceive(Object requestPayload) throws XmlMappingException, WebServiceClientException;
117+
@Nullable Object marshalSendAndReceive(Object requestPayload) throws XmlMappingException, WebServiceClientException;
116118

117119
/**
118120
* Sends a web service message that contains the given payload, marshalled by the
@@ -128,7 +130,7 @@ boolean sendAndReceive(String uri, WebServiceMessageCallback requestCallback,
128130
* @see WebServiceTemplate#setMarshaller(org.springframework.oxm.Marshaller)
129131
* @see WebServiceTemplate#setUnmarshaller(org.springframework.oxm.Unmarshaller)
130132
*/
131-
Object marshalSendAndReceive(String uri, Object requestPayload)
133+
@Nullable Object marshalSendAndReceive(String uri, Object requestPayload)
132134
throws XmlMappingException, WebServiceClientException;
133135

134136
/**
@@ -148,7 +150,7 @@ Object marshalSendAndReceive(String uri, Object requestPayload)
148150
* @see WebServiceTemplate#setMarshaller(org.springframework.oxm.Marshaller)
149151
* @see WebServiceTemplate#setUnmarshaller(org.springframework.oxm.Unmarshaller)
150152
*/
151-
Object marshalSendAndReceive(Object requestPayload, WebServiceMessageCallback requestCallback)
153+
@Nullable Object marshalSendAndReceive(Object requestPayload, @Nullable WebServiceMessageCallback requestCallback)
152154
throws XmlMappingException, WebServiceClientException;
153155

154156
/**
@@ -167,8 +169,8 @@ Object marshalSendAndReceive(Object requestPayload, WebServiceMessageCallback re
167169
* @see WebServiceTemplate#setMarshaller(org.springframework.oxm.Marshaller)
168170
* @see WebServiceTemplate#setUnmarshaller(org.springframework.oxm.Unmarshaller)
169171
*/
170-
Object marshalSendAndReceive(String uri, Object requestPayload, WebServiceMessageCallback requestCallback)
171-
throws XmlMappingException, WebServiceClientException;
172+
@Nullable Object marshalSendAndReceive(String uri, @Nullable Object requestPayload,
173+
@Nullable WebServiceMessageCallback requestCallback) throws XmlMappingException, WebServiceClientException;
172174

173175
// -----------------------------------------------------------------------------------------------------------------
174176
// Convenience methods for sending Sources
@@ -185,7 +187,7 @@ Object marshalSendAndReceive(String uri, Object requestPayload, WebServiceMessag
185187
* @throws WebServiceClientException if there is a problem sending or receiving the
186188
* message
187189
*/
188-
<T> T sendSourceAndReceive(Source requestPayload, SourceExtractor<T> responseExtractor)
190+
<T> @Nullable T sendSourceAndReceive(Source requestPayload, SourceExtractor<T> responseExtractor)
189191
throws WebServiceClientException;
190192

191193
/**
@@ -198,7 +200,7 @@ <T> T sendSourceAndReceive(Source requestPayload, SourceExtractor<T> responseExt
198200
* @throws WebServiceClientException if there is a problem sending or receiving the
199201
* message
200202
*/
201-
<T> T sendSourceAndReceive(String uri, Source requestPayload, SourceExtractor<T> responseExtractor)
203+
<T> @Nullable T sendSourceAndReceive(String uri, Source requestPayload, SourceExtractor<T> responseExtractor)
202204
throws WebServiceClientException;
203205

204206
/**
@@ -216,7 +218,7 @@ <T> T sendSourceAndReceive(String uri, Source requestPayload, SourceExtractor<T>
216218
* @throws WebServiceClientException if there is a problem sending or receiving the
217219
* message
218220
*/
219-
<T> T sendSourceAndReceive(Source requestPayload, WebServiceMessageCallback requestCallback,
221+
<T> @Nullable T sendSourceAndReceive(Source requestPayload, WebServiceMessageCallback requestCallback,
220222
SourceExtractor<T> responseExtractor) throws WebServiceClientException;
221223

222224
/**
@@ -233,8 +235,9 @@ <T> T sendSourceAndReceive(Source requestPayload, WebServiceMessageCallback requ
233235
* @throws WebServiceClientException if there is a problem sending or receiving the
234236
* message
235237
*/
236-
<T> T sendSourceAndReceive(String uri, Source requestPayload, WebServiceMessageCallback requestCallback,
237-
SourceExtractor<T> responseExtractor) throws WebServiceClientException;
238+
<T> @Nullable T sendSourceAndReceive(String uri, Source requestPayload,
239+
@Nullable WebServiceMessageCallback requestCallback, SourceExtractor<T> responseExtractor)
240+
throws WebServiceClientException;
238241

239242
// -----------------------------------------------------------------------------------------------------------------
240243
// Convenience methods for sending Sources and receiving to Results

0 commit comments

Comments
 (0)