Add missing @Nullable annotations on parameters

Issue: SPR-15540
This commit is contained in:
Sebastien Deleuze
2017-05-31 12:37:54 +02:00
parent ad2c0f8410
commit b47d713e14
380 changed files with 1085 additions and 732 deletions

View File

@@ -20,6 +20,7 @@ import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -40,7 +41,7 @@ public abstract class AttributeAccessorSupport implements AttributeAccessor, Ser
@Override
public void setAttribute(String name, Object value) {
public void setAttribute(String name, @Nullable Object value) {
Assert.notNull(name, "Name must not be null");
if (value != null) {
this.attributes.put(name, value);

View File

@@ -189,7 +189,8 @@ public class AnnotatedElementUtils {
final Set<String> types = new LinkedHashSet<>();
searchWithGetSemantics(composed.annotationType(), null, null, null, new SimpleAnnotationProcessor<Object>(true) {
@Override
public Object process(AnnotatedElement annotatedElement, Annotation annotation, int metaDepth) {
@Nullable
public Object process(@Nullable AnnotatedElement annotatedElement, Annotation annotation, int metaDepth) {
types.add(annotation.annotationType().getName());
return CONTINUE;
}
@@ -247,7 +248,8 @@ public class AnnotatedElementUtils {
searchWithGetSemantics(element, annotationType, annotationName, new SimpleAnnotationProcessor<Boolean>() {
@Override
public Boolean process(AnnotatedElement annotatedElement, Annotation annotation, int metaDepth) {
@Nullable
public Boolean process(@Nullable AnnotatedElement annotatedElement, Annotation annotation, int metaDepth) {
return (metaDepth > 0 ? Boolean.TRUE : CONTINUE);
}
}));
@@ -573,7 +575,8 @@ public class AnnotatedElementUtils {
searchWithGetSemantics(element, null, annotationName, new SimpleAnnotationProcessor<Object>() {
@Override
public Object process(AnnotatedElement annotatedElement, Annotation annotation, int metaDepth) {
@Nullable
public Object process(@Nullable AnnotatedElement annotatedElement, Annotation annotation, int metaDepth) {
AnnotationAttributes annotationAttributes = AnnotationUtils.getAnnotationAttributes(
annotation, classValuesAsString, nestedAnnotationsAsMap);
for (Map.Entry<String, Object> entry : annotationAttributes.entrySet()) {
@@ -1459,7 +1462,7 @@ public class AnnotatedElementUtils {
}
@Override
public final void postProcess(AnnotatedElement annotatedElement, Annotation annotation, T result) {
public final void postProcess(@Nullable AnnotatedElement annotatedElement, Annotation annotation, T result) {
// no-op
}
@@ -1484,7 +1487,8 @@ public class AnnotatedElementUtils {
static class AlwaysTrueBooleanAnnotationProcessor extends SimpleAnnotationProcessor<Boolean> {
@Override
public final Boolean process(AnnotatedElement annotatedElement, Annotation annotation, int metaDepth) {
@Nullable
public final Boolean process(@Nullable AnnotatedElement annotatedElement, Annotation annotation, int metaDepth) {
return Boolean.TRUE;
}
}
@@ -1544,13 +1548,14 @@ public class AnnotatedElementUtils {
}
@Override
public AnnotationAttributes process(AnnotatedElement annotatedElement, Annotation annotation, int metaDepth) {
@Nullable
public AnnotationAttributes process(@Nullable AnnotatedElement annotatedElement, Annotation annotation, int metaDepth) {
return AnnotationUtils.retrieveAnnotationAttributes(annotatedElement, annotation,
this.classValuesAsString, this.nestedAnnotationsAsMap);
}
@Override
public void postProcess(AnnotatedElement element, Annotation annotation, AnnotationAttributes attributes) {
public void postProcess(@Nullable AnnotatedElement element, Annotation annotation, AnnotationAttributes attributes) {
annotation = AnnotationUtils.synthesizeAnnotation(annotation, element);
Class<? extends Annotation> targetAnnotationType = attributes.annotationType();

View File

@@ -25,6 +25,7 @@ import reactor.core.publisher.Mono;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
/**
@@ -50,7 +51,7 @@ public abstract class AbstractDecoder<T> implements Decoder<T> {
}
@Override
public boolean canDecode(ResolvableType elementType, MimeType mimeType) {
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
if (mimeType == null) {
return true;
}
@@ -59,7 +60,7 @@ public abstract class AbstractDecoder<T> implements Decoder<T> {
@Override
public Mono<T> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType,
MimeType mimeType, Map<String, Object> hints) {
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
throw new UnsupportedOperationException();
}

View File

@@ -20,6 +20,7 @@ import java.util.Arrays;
import java.util.List;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
/**
@@ -45,7 +46,7 @@ public abstract class AbstractEncoder<T> implements Encoder<T> {
}
@Override
public boolean canEncode(ResolvableType elementType, MimeType mimeType) {
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
if (mimeType == null) {
return true;
}

View File

@@ -24,6 +24,7 @@ import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
/**
@@ -43,7 +44,7 @@ public abstract class AbstractSingleValueEncoder<T> extends AbstractEncoder<T> {
@Override
public final Flux<DataBuffer> encode(Publisher<? extends T> inputStream, DataBufferFactory bufferFactory,
ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
return Flux.from(inputStream).
take(1).

View File

@@ -24,6 +24,7 @@ import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@@ -41,14 +42,14 @@ public class ByteArrayDecoder extends AbstractDecoder<byte[]> {
@Override
public boolean canDecode(ResolvableType elementType, MimeType mimeType) {
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
Class<?> clazz = elementType.getRawClass();
return (super.canDecode(elementType, mimeType) && byte[].class == clazz);
}
@Override
public Flux<byte[]> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
MimeType mimeType, Map<String, Object> hints) {
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
return Flux.from(inputStream).map((dataBuffer) -> {
byte[] result = new byte[dataBuffer.readableByteCount()];

View File

@@ -24,6 +24,7 @@ import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@@ -41,15 +42,15 @@ public class ByteArrayEncoder extends AbstractEncoder<byte[]> {
@Override
public boolean canEncode(ResolvableType elementType, MimeType mimeType) {
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
Class<?> clazz = elementType.resolve(Object.class);
return super.canEncode(elementType, mimeType) && byte[].class.isAssignableFrom(clazz);
}
@Override
public Flux<DataBuffer> encode(Publisher<? extends byte[]> inputStream,
DataBufferFactory bufferFactory, ResolvableType elementType, MimeType mimeType,
Map<String, Object> hints) {
DataBufferFactory bufferFactory, ResolvableType elementType, @Nullable MimeType mimeType,
@Nullable Map<String, Object> hints) {
return Flux.from(inputStream).map(bufferFactory::wrap);
}

View File

@@ -25,6 +25,7 @@ import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@@ -43,14 +44,14 @@ public class ByteBufferDecoder extends AbstractDecoder<ByteBuffer> {
@Override
public boolean canDecode(ResolvableType elementType, MimeType mimeType) {
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
Class<?> clazz = elementType.getRawClass();
return (super.canDecode(elementType, mimeType) && ByteBuffer.class.isAssignableFrom(clazz));
}
@Override
public Flux<ByteBuffer> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
MimeType mimeType, Map<String, Object> hints) {
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
return Flux.from(inputStream).map((dataBuffer) -> {
ByteBuffer copy = ByteBuffer.allocate(dataBuffer.readableByteCount());

View File

@@ -25,6 +25,7 @@ import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@@ -42,15 +43,15 @@ public class ByteBufferEncoder extends AbstractEncoder<ByteBuffer> {
@Override
public boolean canEncode(ResolvableType elementType, MimeType mimeType) {
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
Class<?> clazz = elementType.resolve(Object.class);
return super.canEncode(elementType, mimeType) && ByteBuffer.class.isAssignableFrom(clazz);
}
@Override
public Flux<DataBuffer> encode(Publisher<? extends ByteBuffer> inputStream,
DataBufferFactory bufferFactory, ResolvableType elementType, MimeType mimeType,
Map<String, Object> hints) {
DataBufferFactory bufferFactory, ResolvableType elementType, @Nullable MimeType mimeType,
@Nullable Map<String, Object> hints) {
return Flux.from(inputStream).map(bufferFactory::wrap);
}

View File

@@ -28,6 +28,7 @@ import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@@ -51,7 +52,7 @@ public class CharSequenceEncoder extends AbstractEncoder<CharSequence> {
@Override
public boolean canEncode(ResolvableType elementType, MimeType mimeType) {
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
Class<?> clazz = elementType.resolve(Object.class);
return super.canEncode(elementType, mimeType) && CharSequence.class.isAssignableFrom(clazz);
}
@@ -59,7 +60,7 @@ public class CharSequenceEncoder extends AbstractEncoder<CharSequence> {
@Override
public Flux<DataBuffer> encode(Publisher<? extends CharSequence> inputStream,
DataBufferFactory bufferFactory, ResolvableType elementType,
MimeType mimeType, Map<String, Object> hints) {
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
Charset charset;
if (mimeType != null && mimeType.getCharset() != null) {

View File

@@ -23,6 +23,7 @@ import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@@ -43,14 +44,14 @@ public class DataBufferDecoder extends AbstractDecoder<DataBuffer> {
@Override
public boolean canDecode(ResolvableType elementType, MimeType mimeType) {
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
Class<?> clazz = elementType.getRawClass();
return (super.canDecode(elementType, mimeType) && DataBuffer.class.isAssignableFrom(clazz));
}
@Override
public Flux<DataBuffer> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
MimeType mimeType, Map<String, Object> hints) {
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
return Flux.from(inputStream);
}

View File

@@ -24,6 +24,7 @@ import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@@ -41,15 +42,15 @@ public class DataBufferEncoder extends AbstractEncoder<DataBuffer> {
@Override
public boolean canEncode(ResolvableType elementType, MimeType mimeType) {
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
Class<?> clazz = elementType.resolve(Object.class);
return super.canEncode(elementType, mimeType) && DataBuffer.class.isAssignableFrom(clazz);
}
@Override
public Flux<DataBuffer> encode(Publisher<? extends DataBuffer> inputStream,
DataBufferFactory bufferFactory, ResolvableType elementType, MimeType mimeType,
Map<String, Object> hints) {
DataBufferFactory bufferFactory, ResolvableType elementType, @Nullable MimeType mimeType,
@Nullable Map<String, Object> hints) {
return Flux.from(inputStream);
}

View File

@@ -59,7 +59,7 @@ public interface Decoder<T> {
* @return the output stream with decoded elements
*/
Flux<T> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
@Nullable MimeType mimeType, Map<String, Object> hints);
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints);
/**
* Decode a {@link DataBuffer} input stream into a Mono of {@code T}.
@@ -72,7 +72,7 @@ public interface Decoder<T> {
* @return the output stream with the decoded element
*/
Mono<T> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType,
@Nullable MimeType mimeType, Map<String, Object> hints);
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints);
/**
* Return the list of MIME types this decoder supports.

View File

@@ -64,7 +64,7 @@ public interface Encoder<T> {
* @return the output stream
*/
Flux<DataBuffer> encode(Publisher<? extends T> inputStream, DataBufferFactory bufferFactory,
ResolvableType elementType, @Nullable MimeType mimeType, Map<String, Object> hints);
ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints);
/**
* Return the list of mime types this encoder supports.

View File

@@ -29,6 +29,7 @@ import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@@ -46,7 +47,7 @@ public class ResourceDecoder extends AbstractDecoder<Resource> {
@Override
public boolean canDecode(ResolvableType elementType, MimeType mimeType) {
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
Class<?> clazz = elementType.getRawClass();
return (InputStreamResource.class.equals(clazz) ||
clazz.isAssignableFrom(ByteArrayResource.class)) &&
@@ -55,14 +56,14 @@ public class ResourceDecoder extends AbstractDecoder<Resource> {
@Override
public Flux<Resource> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
MimeType mimeType, Map<String, Object> hints) {
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
return Flux.from(decodeToMono(inputStream, elementType, mimeType, hints));
}
@Override
public Mono<Resource> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType,
MimeType mimeType, Map<String, Object> hints) {
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
Class<?> clazz = elementType.getRawClass();

View File

@@ -30,6 +30,7 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@@ -60,7 +61,7 @@ public class ResourceEncoder extends AbstractSingleValueEncoder<Resource> {
@Override
public boolean canEncode(ResolvableType elementType, MimeType mimeType) {
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
Class<?> clazz = elementType.resolve(Object.class);
return (super.canEncode(elementType, mimeType) && Resource.class.isAssignableFrom(clazz));
}

View File

@@ -37,6 +37,7 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.support.ResourceRegion;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@@ -68,7 +69,7 @@ public class ResourceRegionEncoder extends AbstractEncoder<ResourceRegion> {
}
@Override
public boolean canEncode(ResolvableType elementType, MimeType mimeType) {
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
return super.canEncode(elementType, mimeType)
&& ResourceRegion.class.isAssignableFrom(elementType.resolve(Object.class));
}
@@ -76,7 +77,7 @@ public class ResourceRegionEncoder extends AbstractEncoder<ResourceRegion> {
@Override
@SuppressWarnings("unchecked")
public Flux<DataBuffer> encode(Publisher<? extends ResourceRegion> inputStream,
DataBufferFactory bufferFactory, ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
DataBufferFactory bufferFactory, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
Assert.notNull(inputStream, "'inputStream' must not be null");
Assert.notNull(bufferFactory, "'bufferFactory' must not be null");

View File

@@ -31,6 +31,7 @@ import reactor.core.publisher.Mono;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@@ -70,14 +71,14 @@ public class StringDecoder extends AbstractDecoder<String> {
@Override
public boolean canDecode(ResolvableType elementType, MimeType mimeType) {
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
return (super.canDecode(elementType, mimeType) &&
String.class.equals(elementType.getRawClass()));
}
@Override
public Flux<String> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
MimeType mimeType, Map<String, Object> hints) {
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
Flux<DataBuffer> inputFlux = Flux.from(inputStream);
if (this.splitOnNewline) {
@@ -88,7 +89,7 @@ public class StringDecoder extends AbstractDecoder<String> {
@Override
public Mono<String> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType,
MimeType mimeType, Map<String, Object> hints) {
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
return Flux.from(inputStream)
.reduce(DataBuffer::write)

View File

@@ -24,6 +24,7 @@ import java.util.Set;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -59,7 +60,7 @@ final class ArrayToArrayConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (this.conversionService instanceof GenericConversionService &&
((GenericConversionService) this.conversionService).canBypassConvert(
sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor())) {

View File

@@ -25,6 +25,7 @@ import org.springframework.core.CollectionFactory;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
/**
* Converts an array to a Collection.
@@ -60,7 +61,8 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}

View File

@@ -23,6 +23,7 @@ import java.util.Set;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
/**
* Converts an array to an Object by returning the first array element
@@ -52,7 +53,8 @@ final class ArrayToObjectConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}

View File

@@ -23,6 +23,7 @@ import java.util.Set;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -54,7 +55,8 @@ final class ArrayToStringConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType);
}

View File

@@ -25,6 +25,7 @@ import java.util.Set;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
/**
* Converts a {@link ByteBuffer} directly to and from {@code byte[]}s and indirectly
@@ -85,7 +86,8 @@ final class ByteBufferConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
boolean byteBufferTarget = targetType.isAssignableTo(BYTE_BUFFER_TYPE);
if (source instanceof ByteBuffer) {
ByteBuffer buffer = (ByteBuffer) source;

View File

@@ -24,6 +24,7 @@ import java.util.Set;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
/**
* Converts a Collection to an array.
@@ -55,7 +56,8 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}

View File

@@ -24,6 +24,7 @@ import org.springframework.core.CollectionFactory;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
/**
* Converts from a Collection to another Collection.
@@ -59,7 +60,8 @@ final class CollectionToCollectionConverter implements ConditionalGenericConvert
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}

View File

@@ -23,6 +23,7 @@ import java.util.Set;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
/**
* Converts a Collection to an Object by returning the first collection element after converting it to the desired targetType.
@@ -49,7 +50,8 @@ final class CollectionToObjectConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}

View File

@@ -23,6 +23,7 @@ import java.util.Set;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
/**
* Converts a Collection to a comma-delimited String.
@@ -54,7 +55,8 @@ final class CollectionToStringConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}

View File

@@ -22,6 +22,7 @@ import java.util.Set;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
/**
* Simply calls {@link Object#toString()} to convert any supported object
@@ -60,7 +61,8 @@ final class FallbackObjectToStringConverter implements ConditionalGenericConvert
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
return (source != null ? source.toString() : null);
}

View File

@@ -131,14 +131,14 @@ public class GenericConversionService implements ConfigurableConversionService {
// ConversionService implementation
@Override
public boolean canConvert(Class<?> sourceType, Class<?> targetType) {
public boolean canConvert(@Nullable Class<?> sourceType, Class<?> targetType) {
Assert.notNull(targetType, "Target type to convert to cannot be null");
return canConvert((sourceType != null ? TypeDescriptor.valueOf(sourceType) : null),
TypeDescriptor.valueOf(targetType));
}
@Override
public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType) {
public boolean canConvert(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType) {
Assert.notNull(targetType, "Target type to convert to cannot be null");
if (sourceType == null) {
return true;
@@ -169,13 +169,13 @@ public class GenericConversionService implements ConfigurableConversionService {
@Override
@SuppressWarnings("unchecked")
public <T> T convert(Object source, Class<T> targetType) {
public <T> T convert(@Nullable Object source, Class<T> targetType) {
Assert.notNull(targetType, "Target type to convert to cannot be null");
return (T) convert(source, TypeDescriptor.forObject(source), TypeDescriptor.valueOf(targetType));
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
public Object convert(@Nullable Object source, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType) {
Assert.notNull(targetType, "Target type to convert to cannot be null");
if (sourceType == null) {
Assert.isTrue(source == null, "Source must be [null] if source type == [null]");
@@ -372,7 +372,8 @@ public class GenericConversionService implements ConfigurableConversionService {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return convertNullSource(sourceType, targetType);
}
@@ -422,7 +423,7 @@ public class GenericConversionService implements ConfigurableConversionService {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return convertNullSource(sourceType, targetType);
}
@@ -691,7 +692,7 @@ public class GenericConversionService implements ConfigurableConversionService {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
return source;
}

View File

@@ -62,7 +62,8 @@ final class IdToEntityConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}

View File

@@ -26,6 +26,7 @@ import org.springframework.core.CollectionFactory;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
/**
* Converts a Map to another Map.
@@ -61,7 +62,7 @@ final class MapToMapConverter implements ConditionalGenericConverter {
@Override
@SuppressWarnings("unchecked")
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}

View File

@@ -23,6 +23,7 @@ import java.util.Set;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
/**
* Converts an Object to a single-element array containing the Object.
@@ -52,7 +53,8 @@ final class ObjectToArrayConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}

View File

@@ -24,6 +24,7 @@ import org.springframework.core.CollectionFactory;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
/**
* Converts an Object to a single-element Collection containing the Object.
@@ -54,7 +55,8 @@ final class ObjectToCollectionConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}

View File

@@ -28,6 +28,7 @@ import java.util.Set;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ReflectionUtils;
@@ -81,7 +82,8 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}

View File

@@ -23,6 +23,7 @@ import java.util.Set;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
/**
* Convert an Object to {@code java.util.Optional<T>} if necessary using the
@@ -59,7 +60,8 @@ final class ObjectToOptionalConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return Optional.empty();
}

View File

@@ -26,6 +26,7 @@ import java.util.stream.Stream;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
/**
* Converts a {@link Stream} to and from a collection or array, converting the
@@ -87,7 +88,8 @@ class StreamConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (sourceType.isAssignableTo(STREAM_TYPE)) {
return convertFromStream((Stream<?>) source, sourceType, targetType);
}

View File

@@ -23,6 +23,7 @@ import java.util.Set;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -51,7 +52,8 @@ final class StringToArrayConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}

View File

@@ -24,6 +24,7 @@ import org.springframework.core.CollectionFactory;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -57,7 +58,8 @@ final class StringToCollectionConverter implements ConditionalGenericConverter {
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (source == null) {
return null;
}

View File

@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.core.SpringProperties;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -496,7 +497,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
}
@Override
public void setValueSeparator(String valueSeparator) {
public void setValueSeparator(@Nullable String valueSeparator) {
this.propertyResolver.setValueSeparator(valueSeparator);
}

View File

@@ -109,7 +109,7 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
* @see org.springframework.util.SystemPropertyUtils#VALUE_SEPARATOR
*/
@Override
public void setValueSeparator(String valueSeparator) {
public void setValueSeparator(@Nullable String valueSeparator) {
this.valueSeparator = valueSeparator;
}

View File

@@ -23,6 +23,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
@@ -49,7 +50,7 @@ public class DefaultValueStyler implements ValueStyler {
@Override
public String style(Object value) {
public String style(@Nullable Object value) {
if (value == null) {
return NULL;
}

View File

@@ -263,7 +263,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
private V put(final K key, final V value, final boolean overwriteExisting) {
return doTask(key, new Task<V>(TaskOption.RESTRUCTURE_BEFORE, TaskOption.RESIZE) {
@Override
protected V execute(Reference<K, V> reference, Entry<K, V> entry, Entries entries) {
@Nullable
protected V execute(@Nullable Reference<K, V> reference, @Nullable Entry<K, V> entry, Entries entries) {
if (entry != null) {
V previousValue = entry.getValue();
if (overwriteExisting) {
@@ -281,7 +282,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
public V remove(Object key) {
return doTask(key, new Task<V>(TaskOption.RESTRUCTURE_AFTER, TaskOption.SKIP_IF_EMPTY) {
@Override
protected V execute(Reference<K, V> reference, Entry<K, V> entry) {
@Nullable
protected V execute(@Nullable Reference<K, V> reference, @Nullable Entry<K, V> entry) {
if (entry != null) {
reference.release();
return entry.value;
@@ -295,7 +297,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
public boolean remove(Object key, final Object value) {
return doTask(key, new Task<Boolean>(TaskOption.RESTRUCTURE_AFTER, TaskOption.SKIP_IF_EMPTY) {
@Override
protected Boolean execute(Reference<K, V> reference, Entry<K, V> entry) {
@Nullable
protected Boolean execute(@Nullable Reference<K, V> reference, @Nullable Entry<K, V> entry) {
if (entry != null && ObjectUtils.nullSafeEquals(entry.getValue(), value)) {
reference.release();
return true;
@@ -309,7 +312,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
public boolean replace(K key, final V oldValue, final V newValue) {
return doTask(key, new Task<Boolean>(TaskOption.RESTRUCTURE_BEFORE, TaskOption.SKIP_IF_EMPTY) {
@Override
protected Boolean execute(Reference<K, V> reference, Entry<K, V> entry) {
@Nullable
protected Boolean execute(@Nullable Reference<K, V> reference, @Nullable Entry<K, V> entry) {
if (entry != null && ObjectUtils.nullSafeEquals(entry.getValue(), oldValue)) {
entry.setValue(newValue);
return true;
@@ -324,7 +328,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
public V replace(K key, final V value) {
return doTask(key, new Task<V>(TaskOption.RESTRUCTURE_BEFORE, TaskOption.SKIP_IF_EMPTY) {
@Override
protected V execute(Reference<K, V> reference, Entry<K, V> entry) {
@Nullable
protected V execute(@Nullable Reference<K, V> reference, @Nullable Entry<K, V> entry) {
if (entry != null) {
V previousValue = entry.getValue();
entry.setValue(value);

View File

@@ -119,8 +119,7 @@ public abstract class ReflectionUtils {
* @param target the target object on which to set the field
* @param value the value to set (may be {@code null})
*/
@Nullable
public static void setField(Field field, Object target, Object value) {
public static void setField(Field field, Object target, @Nullable Object value) {
try {
field.set(target, value);
}