Skip to content

Commit 336b366

Browse files
authored
GH-10083: Implement Nullability in XML module
Related to: #10083 * Add `@org.jspecify.annotations.NullMarked` to all the packages in the XML module * Apply JSpecify null safety annotation improvements Signed-off-by: Eddie Cho <[email protected]>
1 parent e21d843 commit 336b366

21 files changed

+65
-37
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Contains parser classes for the XML namespace support.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.integration.xml.config;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Root package of the XML Module.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.integration.xml;

spring-integration-xml/src/main/java/org/springframework/integration/xml/result/package-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
* will return {@link javax.xml.transform.Result}, possibly taking into account
44
* payload instance.
55
*/
6+
@org.jspecify.annotations.NullMarked
67
package org.springframework.integration.xml.result;

spring-integration-xml/src/main/java/org/springframework/integration/xml/router/XPathRouter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24+
import org.jspecify.annotations.Nullable;
2425
import org.w3c.dom.DOMException;
2526
import org.w3c.dom.Node;
2627

@@ -128,7 +129,7 @@ private static class TextContentNodeMapper implements NodeMapper<Object> {
128129
}
129130

130131
@Override
131-
public Object mapNode(Node node, int nodeNum) throws DOMException {
132+
public @Nullable Object mapNode(Node node, int nodeNum) throws DOMException {
132133
return node.getTextContent();
133134
}
134135

spring-integration-xml/src/main/java/org/springframework/integration/xml/selector/XmlValidatingMessageSelector.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.UncheckedIOException;
2121
import java.util.Arrays;
2222

23+
import org.jspecify.annotations.Nullable;
2324
import org.xml.sax.SAXParseException;
2425

2526
import org.springframework.core.io.Resource;
@@ -83,7 +84,7 @@ public String getUrl() {
8384
* @param schemaType The schema type.
8485
* @throws IOException if the XmlValidatorFactory fails to create a validator
8586
*/
86-
public XmlValidatingMessageSelector(Resource schema, SchemaType schemaType) throws IOException {
87+
public XmlValidatingMessageSelector(Resource schema, @Nullable SchemaType schemaType) throws IOException {
8788
this(XmlValidatorFactory.createValidator(schema,
8889
schemaType == null
8990
? SchemaType.XML_SCHEMA.getUrl()
@@ -95,7 +96,7 @@ public XmlValidatingMessageSelector(XmlValidator xmlValidator) {
9596
this.xmlValidator = xmlValidator;
9697
}
9798

98-
public XmlValidatingMessageSelector(Resource schema, String schemaType) throws IOException {
99+
public XmlValidatingMessageSelector(Resource schema, @Nullable String schemaType) throws IOException {
99100
this(schema,
100101
StringUtils.hasText(schemaType)
101102
? SchemaType.valueOf(schemaType.toUpperCase().replaceFirst("-", "_"))

spring-integration-xml/src/main/java/org/springframework/integration/xml/selector/package-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
* Provides XML-centric {@link org.springframework.integration.core.MessageSelector}
33
* implementations.
44
*/
5+
@org.jspecify.annotations.NullMarked
56
package org.springframework.integration.xml.selector;

spring-integration-xml/src/main/java/org/springframework/integration/xml/source/package-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
* Provides various {@link org.springframework.integration.xml.source.SourceFactory}
33
* implementations.
44
*/
5+
@org.jspecify.annotations.NullMarked
56
package org.springframework.integration.xml.source;

spring-integration-xml/src/main/java/org/springframework/integration/xml/splitter/XPathMessageSplitter.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import javax.xml.xpath.XPathExpressionException;
3939
import javax.xml.xpath.XPathFactory;
4040

41+
import org.jspecify.annotations.Nullable;
4142
import org.w3c.dom.Document;
4243
import org.w3c.dom.Node;
4344
import org.w3c.dom.NodeList;
@@ -82,15 +83,15 @@ public class XPathMessageSplitter extends AbstractMessageSplitter {
8283

8384
private final XPathExpression xpathExpression;
8485

85-
private javax.xml.xpath.XPathExpression jaxpExpression;
86+
private javax.xml.xpath.@Nullable XPathExpression jaxpExpression;
8687

8788
private boolean createDocuments;
8889

8990
private DocumentBuilderFactory documentBuilderFactory;
9091

9192
private XmlPayloadConverter xmlPayloadConverter = new DefaultXmlPayloadConverter();
9293

93-
private Properties outputProperties;
94+
private @Nullable Properties outputProperties;
9495

9596
private boolean returnIterator = true;
9697

@@ -292,7 +293,7 @@ private Object splitDocument(Document document) throws ParserConfigurationExcept
292293
}
293294

294295
private Object splitNode(Node node) throws ParserConfigurationException {
295-
if (this.returnIterator) {
296+
if (this.returnIterator && this.jaxpExpression != null) {
296297
try {
297298
NodeList nodeList = (NodeList) this.jaxpExpression.evaluate(node, XPathConstants.NODESET);
298299
return new NodeListIterator(nodeList);
@@ -338,7 +339,7 @@ private DocumentBuilder getNewDocumentBuilder() throws ParserConfigurationExcept
338339

339340
private final class NodeListIterator implements Iterator<Node> {
340341

341-
private final DocumentBuilder documentBuilder;
342+
private final @Nullable DocumentBuilder documentBuilder;
342343

343344
private final NodeList nodeList;
344345

@@ -360,7 +361,7 @@ public boolean hasNext() {
360361
}
361362

362363
@Override
363-
public Node next() {
364+
public @Nullable Node next() {
364365
if (!hasNext()) {
365366
return null;
366367
}

spring-integration-xml/src/main/java/org/springframework/integration/xml/splitter/package-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
* Provides implementations of
33
* {@link org.springframework.integration.splitter.AbstractMessageSplitter}.
44
*/
5+
@org.jspecify.annotations.NullMarked
56
package org.springframework.integration.xml.splitter;

spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/AbstractXmlTransformer.java

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

1717
package org.springframework.integration.xml.transformer;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.beans.factory.BeanFactory;
2022
import org.springframework.integration.transformer.AbstractTransformer;
2123
import org.springframework.integration.xml.result.DomResultFactory;
@@ -39,9 +41,9 @@ public abstract class AbstractXmlTransformer extends AbstractTransformer {
3941

4042
public static final String STRING_RESULT = "StringResult";
4143

42-
private volatile String resultType;
44+
private volatile @Nullable String resultType;
4345

44-
private volatile String resultFactoryName;
46+
private volatile @Nullable String resultFactoryName;
4547

4648
private volatile ResultFactory resultFactory = new DomResultFactory();
4749

@@ -58,11 +60,11 @@ public void setResultFactory(ResultFactory resultFactory) {
5860
this.resultFactory = resultFactory;
5961
}
6062

61-
public String getResultType() {
63+
public @Nullable String getResultType() {
6264
return this.resultType;
6365
}
6466

65-
public String getResultFactoryName() {
67+
public @Nullable String getResultFactoryName() {
6668
return this.resultFactoryName;
6769
}
6870

@@ -85,7 +87,7 @@ protected void onInit() {
8587
* a bean definition for a {@link ResultFactory} based on either the
8688
* 'result-factory' or 'result-type' attributes.
8789
*/
88-
private ResultFactory configureResultFactory(String resultType, String resultFactoryName, BeanFactory beanFactory) {
90+
private @Nullable ResultFactory configureResultFactory(@Nullable String resultType, @Nullable String resultFactoryName, BeanFactory beanFactory) {
8991
boolean bothHaveText = StringUtils.hasText(resultFactoryName) && StringUtils.hasText(resultType);
9092
ResultFactory configuredResultFactory = null;
9193
Assert.state(!bothHaveText, "Only one of 'result-factory' or 'result-type' should be specified.");

0 commit comments

Comments
 (0)