Consistent use of @Nullable across the codebase (even for internals)
Beyond just formally declaring the current behavior, this revision actually enforces non-null behavior in selected signatures now, not tolerating null values anymore when not explicitly documented. It also changes some utility methods with historic null-in/null-out tolerance towards enforced non-null return values, making them a proper citizen in non-null assignments. Some issues are left as to-do: in particular a thorough revision of spring-test, and a few tests with unclear failures (ignored as "TODO: NULLABLE") to be sorted out in a follow-up commit. Issue: SPR-15540
This commit is contained in:
@@ -429,7 +429,7 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.beanClassLoader = classLoader;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,8 @@ class ClassPathJaxb2TypeScanner {
|
||||
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
|
||||
if (isJaxb2Class(metadataReader, metadataReaderFactory)) {
|
||||
String className = metadataReader.getClassMetadata().getClassName();
|
||||
Class<?> jaxb2AnnotatedClass = this.resourcePatternResolver.getClassLoader().loadClass(className);
|
||||
Class<?> jaxb2AnnotatedClass =
|
||||
ClassUtils.forName(className, this.resourcePatternResolver.getClassLoader());
|
||||
jaxb2Classes.add(jaxb2AnnotatedClass);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,7 +432,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.beanClassLoader = classLoader;
|
||||
}
|
||||
|
||||
@@ -1001,7 +1001,11 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
||||
}
|
||||
contentId = '<' + contentId + '>';
|
||||
}
|
||||
return this.mimeContainer.getAttachment(contentId);
|
||||
DataHandler dataHandler = this.mimeContainer.getAttachment(contentId);
|
||||
if (dataHandler == null) {
|
||||
throw new IllegalArgumentException("No attachment found for " + contentId);
|
||||
}
|
||||
return dataHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -419,7 +419,7 @@ public class JibxMarshaller extends AbstractMarshaller implements InitializingBe
|
||||
return transformAndUnmarshal(new SAXSource(xmlReader, inputSource), inputSource.getEncoding());
|
||||
}
|
||||
|
||||
private Object transformAndUnmarshal(Source source, String encoding) throws IOException {
|
||||
private Object transformAndUnmarshal(Source source, @Nullable String encoding) throws IOException {
|
||||
try {
|
||||
Transformer transformer = this.transformerFactory.newTransformer();
|
||||
if (encoding != null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,6 +32,7 @@ import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.ext.LexicalHandler;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -130,6 +131,7 @@ public class MarshallingSource extends SAXSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ContentHandler getContentHandler() {
|
||||
return this.contentHandler;
|
||||
}
|
||||
@@ -140,6 +142,7 @@ public class MarshallingSource extends SAXSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public DTDHandler getDTDHandler() {
|
||||
return this.dtdHandler;
|
||||
}
|
||||
@@ -150,6 +153,7 @@ public class MarshallingSource extends SAXSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public EntityResolver getEntityResolver() {
|
||||
return this.entityResolver;
|
||||
}
|
||||
@@ -160,6 +164,7 @@ public class MarshallingSource extends SAXSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ErrorHandler getErrorHandler() {
|
||||
return this.errorHandler;
|
||||
}
|
||||
|
||||
@@ -380,7 +380,7 @@ public class XStreamMarshaller extends AbstractMarshaller implements BeanClassLo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.beanClassLoader = classLoader;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user