Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Contains parser classes for the XML namespace support.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.xml.config;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Root package of the XML Module.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.xml;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
* will return {@link javax.xml.transform.Result}, possibly taking into account
* payload instance.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.xml.result;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;

import org.jspecify.annotations.Nullable;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;

Expand Down Expand Up @@ -128,7 +129,7 @@ private static class TextContentNodeMapper implements NodeMapper<Object> {
}

@Override
public Object mapNode(Node node, int nodeNum) throws DOMException {
public @Nullable Object mapNode(Node node, int nodeNum) throws DOMException {
return node.getTextContent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.UncheckedIOException;
import java.util.Arrays;

import org.jspecify.annotations.Nullable;
import org.xml.sax.SAXParseException;

import org.springframework.core.io.Resource;
Expand Down Expand Up @@ -83,7 +84,7 @@ public String getUrl() {
* @param schemaType The schema type.
* @throws IOException if the XmlValidatorFactory fails to create a validator
*/
public XmlValidatingMessageSelector(Resource schema, SchemaType schemaType) throws IOException {
public XmlValidatingMessageSelector(Resource schema, @Nullable SchemaType schemaType) throws IOException {
this(XmlValidatorFactory.createValidator(schema,
schemaType == null
? SchemaType.XML_SCHEMA.getUrl()
Expand All @@ -95,7 +96,7 @@ public XmlValidatingMessageSelector(XmlValidator xmlValidator) {
this.xmlValidator = xmlValidator;
}

public XmlValidatingMessageSelector(Resource schema, String schemaType) throws IOException {
public XmlValidatingMessageSelector(Resource schema, @Nullable String schemaType) throws IOException {
this(schema,
StringUtils.hasText(schemaType)
? SchemaType.valueOf(schemaType.toUpperCase().replaceFirst("-", "_"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
* Provides XML-centric {@link org.springframework.integration.core.MessageSelector}
* implementations.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.xml.selector;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
* Provides various {@link org.springframework.integration.xml.source.SourceFactory}
* implementations.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.xml.source;
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.jspecify.annotations.Nullable;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
Expand Down Expand Up @@ -82,15 +83,15 @@ public class XPathMessageSplitter extends AbstractMessageSplitter {

private final XPathExpression xpathExpression;

private javax.xml.xpath.XPathExpression jaxpExpression;
private javax.xml.xpath.@Nullable XPathExpression jaxpExpression;

private boolean createDocuments;

private DocumentBuilderFactory documentBuilderFactory;

private XmlPayloadConverter xmlPayloadConverter = new DefaultXmlPayloadConverter();

private Properties outputProperties;
private @Nullable Properties outputProperties;

private boolean returnIterator = true;

Expand Down Expand Up @@ -292,7 +293,7 @@ private Object splitDocument(Document document) throws ParserConfigurationExcept
}

private Object splitNode(Node node) throws ParserConfigurationException {
if (this.returnIterator) {
if (this.returnIterator && this.jaxpExpression != null) {
try {
NodeList nodeList = (NodeList) this.jaxpExpression.evaluate(node, XPathConstants.NODESET);
return new NodeListIterator(nodeList);
Expand Down Expand Up @@ -338,7 +339,7 @@ private DocumentBuilder getNewDocumentBuilder() throws ParserConfigurationExcept

private final class NodeListIterator implements Iterator<Node> {

private final DocumentBuilder documentBuilder;
private final @Nullable DocumentBuilder documentBuilder;

private final NodeList nodeList;

Expand All @@ -360,7 +361,7 @@ public boolean hasNext() {
}

@Override
public Node next() {
public @Nullable Node next() {
if (!hasNext()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
* Provides implementations of
* {@link org.springframework.integration.splitter.AbstractMessageSplitter}.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.xml.splitter;
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.integration.xml.transformer;

import org.jspecify.annotations.Nullable;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.transformer.AbstractTransformer;
import org.springframework.integration.xml.result.DomResultFactory;
Expand All @@ -39,9 +41,9 @@ public abstract class AbstractXmlTransformer extends AbstractTransformer {

public static final String STRING_RESULT = "StringResult";

private volatile String resultType;
private volatile @Nullable String resultType;

private volatile String resultFactoryName;
private volatile @Nullable String resultFactoryName;

private volatile ResultFactory resultFactory = new DomResultFactory();

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

public String getResultType() {
public @Nullable String getResultType() {
return this.resultType;
}

public String getResultFactoryName() {
public @Nullable String getResultFactoryName() {
return this.resultFactoryName;
}

Expand All @@ -85,7 +87,7 @@ protected void onInit() {
* a bean definition for a {@link ResultFactory} based on either the
* 'result-factory' or 'result-type' attributes.
*/
private ResultFactory configureResultFactory(String resultType, String resultFactoryName, BeanFactory beanFactory) {
private @Nullable ResultFactory configureResultFactory(@Nullable String resultType, @Nullable String resultFactoryName, BeanFactory beanFactory) {
boolean bothHaveText = StringUtils.hasText(resultFactoryName) && StringUtils.hasText(resultType);
ResultFactory configuredResultFactory = null;
Assert.state(!bothHaveText, "Only one of 'result-factory' or 'result-type' should be specified.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import javax.xml.transform.Result;

import org.jspecify.annotations.Nullable;

import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
import org.springframework.oxm.Marshaller;
Expand All @@ -39,11 +41,11 @@ public class MarshallingTransformer extends AbstractXmlTransformer {

private final Marshaller marshaller;

private final ResultTransformer resultTransformer;
private final @Nullable ResultTransformer resultTransformer;

private volatile boolean extractPayload = true;

public MarshallingTransformer(Marshaller marshaller, ResultTransformer resultTransformer) {
public MarshallingTransformer(Marshaller marshaller, @Nullable ResultTransformer resultTransformer) {
Assert.notNull(marshaller, "a marshaller is required");
this.marshaller = marshaller;
this.resultTransformer = resultTransformer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;

import org.jspecify.annotations.Nullable;

import org.springframework.messaging.MessagingException;
import org.springframework.util.Assert;
import org.springframework.xml.transform.StringResult;
Expand All @@ -48,7 +50,7 @@ public class ResultToStringTransformer implements ResultTransformer {

private final TransformerFactory transformerFactory;

private Properties outputProperties;
private @Nullable Properties outputProperties;

public ResultToStringTransformer() {
this.transformerFactory = TransformerFactoryUtils.newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;

import org.jspecify.annotations.Nullable;
import org.w3c.dom.Document;

import org.springframework.integration.transformer.AbstractPayloadTransformer;
Expand Down Expand Up @@ -68,7 +69,7 @@ public class UnmarshallingTransformer extends AbstractPayloadTransformer<Object,

private boolean alwaysUseSourceFactory = false;

private MimeMessageUnmarshallerHelper mimeMessageUnmarshallerHelper;
private @Nullable MimeMessageUnmarshallerHelper mimeMessageUnmarshallerHelper;

public UnmarshallingTransformer(Unmarshaller unmarshaller) {
this.unmarshaller = unmarshaller;
Expand Down Expand Up @@ -162,7 +163,7 @@ private static class MimeMessageUnmarshallerHelper {
this.delegate = unmarshaller;
}

Object maybeUnmarshalMimeMessage(Object payload) throws IOException {
@Nullable Object maybeUnmarshalMimeMessage(Object payload) throws IOException {
if (payload instanceof org.springframework.ws.mime.MimeMessage mimeMessage) {
return org.springframework.ws.support.MarshallingUtils.unmarshal(this.delegate,
mimeMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.integration.xml.transformer;

import org.jspecify.annotations.Nullable;
import org.w3c.dom.Node;

import org.springframework.integration.transformer.AbstractTransformer;
Expand Down Expand Up @@ -50,7 +51,7 @@ public class XPathTransformer extends AbstractTransformer {

private volatile XPathEvaluationType evaluationType = XPathEvaluationType.STRING_RESULT;

private volatile NodeMapper<?> nodeMapper;
private volatile @Nullable NodeMapper<?> nodeMapper;

/**
* Create an {@link XPathTransformer} that will create an XPath expression from the given String
Expand Down Expand Up @@ -110,7 +111,7 @@ public String getComponentType() {
}

@Override
protected Object doTransform(Message<?> message) {
protected @Nullable Object doTransform(Message<?> message) {
Node node = this.converter.convertToNode(message.getPayload());
Object result = null;
if (this.nodeMapper != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;

import org.jspecify.annotations.Nullable;
import org.w3c.dom.Document;

import org.springframework.beans.factory.BeanClassLoaderAware;
Expand Down Expand Up @@ -89,17 +90,19 @@
*/
public class XsltPayloadTransformer extends AbstractXmlTransformer implements BeanClassLoaderAware {

private final ResultTransformer resultTransformer;
private final @Nullable ResultTransformer resultTransformer;

private final Resource xslResource;
private final @Nullable Resource xslResource;

@SuppressWarnings("NullAway.Init")
private Templates templates;

private String transformerFactoryClassName;
private @Nullable String transformerFactoryClassName;

@SuppressWarnings("NullAway.Init")
private volatile StandardEvaluationContext evaluationContext;

private Map<String, Expression> xslParameterMappings;
private @Nullable Map<String, Expression> xslParameterMappings;

private SourceFactory sourceFactory = new DomSourceFactory();

Expand All @@ -109,15 +112,15 @@ public class XsltPayloadTransformer extends AbstractXmlTransformer implements Be

private boolean alwaysUseResultFactory = false;

private String[] xsltParamHeaders;
private String @Nullable [] xsltParamHeaders;

public XsltPayloadTransformer(Templates templates) {
this(templates, null);
}

private ClassLoader classLoader;
private @Nullable ClassLoader classLoader;

public XsltPayloadTransformer(Templates templates, ResultTransformer resultTransformer) {
public XsltPayloadTransformer(Templates templates, @Nullable ResultTransformer resultTransformer) {
Assert.notNull(templates, "'templates' must not be null.");
this.templates = templates;
this.resultTransformer = resultTransformer;
Expand All @@ -136,8 +139,8 @@ public XsltPayloadTransformer(Resource xslResource, String transformerFactoryCla
this(xslResource, null, transformerFactoryClassName);
}

public XsltPayloadTransformer(Resource xslResource, ResultTransformer resultTransformer,
String transformerFactoryClassName) {
public XsltPayloadTransformer(Resource xslResource, @Nullable ResultTransformer resultTransformer,
@Nullable String transformerFactoryClassName) {

Assert.notNull(xslResource, "'xslResource' must not be null.");
Assert.isTrue(xslResource instanceof ClassPathResource ||
Expand Down Expand Up @@ -230,6 +233,7 @@ protected void onInit() {
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
if (this.templates == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You marked it as @SuppressWarnings("NullAway.Init"), and I understand why.
But doesn't this if complain that the property is never null?
Thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, looks like that work.
Just did something similar in Zip module: e21d843#diff-9f1c53dcaacbf6eb4a502eeb67a286da470aabb2b9401c05c50f5bc0788fa76dR64
And only what I see is a complain from my IntelliJ IDEA.
JSpecify compiler plugin is good with that.
So, merging your contribution as is.

Thank you!

try {
Assert.notNull(this.xslResource, "'xslResource' must not be null.");
TransformerFactory transformerFactory = createTransformerFactory();
this.templates = transformerFactory.newTemplates(createStreamSourceOnResource(this.xslResource));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Provides Transformer and Enricher implementations.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.xml.transformer;
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.integration.xml.transformer.support;

import org.jspecify.annotations.Nullable;
import org.w3c.dom.Node;

import org.springframework.beans.BeansException;
Expand Down Expand Up @@ -55,9 +56,9 @@ public class XPathExpressionEvaluatingHeaderValueMessageProcessor implements Hea

private XPathEvaluationType evaluationType = XPathEvaluationType.STRING_RESULT;

private TypeDescriptor headerTypeDescriptor;
private @Nullable TypeDescriptor headerTypeDescriptor;

private Boolean overwrite;
private @Nullable Boolean overwrite;

public XPathExpressionEvaluatingHeaderValueMessageProcessor(String expression) {
this(expression, new DefaultXmlPayloadConverter());
Expand Down Expand Up @@ -107,7 +108,7 @@ public void setOverwrite(Boolean overwrite) {
}

@Override
public Boolean isOverwrite() {
public @Nullable Boolean isOverwrite() {
return this.overwrite;
}

Expand All @@ -120,7 +121,7 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
}

@Override
public Object processMessage(Message<?> message) {
public @Nullable Object processMessage(Message<?> message) {
Node node = this.converter.convertToNode(message.getPayload());
Object result = this.evaluationType.evaluateXPath(this.expression, node);
if (result instanceof String string && string.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
* @since 3.0
*
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.xml.transformer.support;
Loading