From 01d86dc498f95943f83df2a38dfbcdd9a8d45b00 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 7 Oct 2020 14:28:45 +0200 Subject: [PATCH] Consistent @Nullable declarations on overridden converter methods --- .../core/convert/support/GenericConversionService.java | 5 +++-- .../core/convert/support/MapToMapConverter.java | 4 ++-- .../core/convert/support/StringToBooleanConverter.java | 2 ++ .../core/convert/support/StringToCharacterConverter.java | 4 +++- .../core/convert/support/StringToEnumConverterFactory.java | 4 +++- .../core/convert/support/StringToNumberConverterFactory.java | 4 +++- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index a36726728dc..7fa3206a40f 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -642,7 +642,7 @@ public class GenericConversionService implements ConfigurableConversionService { private List getConverterStrings() { List converterStrings = new ArrayList<>(); - for (ConvertersForPair convertersForPair : converters.values()) { + for (ConvertersForPair convertersForPair : this.converters.values()) { converterStrings.add(convertersForPair.toString()); } Collections.sort(converterStrings); @@ -692,6 +692,7 @@ public class GenericConversionService implements ConfigurableConversionService { } @Override + @Nullable public Set getConvertibleTypes() { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java index 9da79dd70b9..5b791f966d6 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -61,12 +61,12 @@ final class MapToMapConverter implements ConditionalGenericConverter { } @Override - @SuppressWarnings("unchecked") @Nullable public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } + @SuppressWarnings("unchecked") Map sourceMap = (Map) source; // Shortcut if possible... diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java index a476de69cca..4b1c0fd7b2d 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java @@ -20,6 +20,7 @@ import java.util.HashSet; import java.util.Set; import org.springframework.core.convert.converter.Converter; +import org.springframework.lang.Nullable; /** * Converts String to a Boolean. @@ -48,6 +49,7 @@ final class StringToBooleanConverter implements Converter { @Override + @Nullable public Boolean convert(String source) { String value = source.trim(); if (value.isEmpty()) { diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToCharacterConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToCharacterConverter.java index dc4daa9bd42..97374fbba74 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToCharacterConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToCharacterConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -17,6 +17,7 @@ package org.springframework.core.convert.support; import org.springframework.core.convert.converter.Converter; +import org.springframework.lang.Nullable; /** * Converts a String to a Character. @@ -27,6 +28,7 @@ import org.springframework.core.convert.converter.Converter; final class StringToCharacterConverter implements Converter { @Override + @Nullable public Character convert(String source) { if (source.isEmpty()) { return null; diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java index 6a0c3ba395d..bf4d7fb2c14 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -18,6 +18,7 @@ package org.springframework.core.convert.support; import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConverterFactory; +import org.springframework.lang.Nullable; /** * Converts from a String to a {@link java.lang.Enum} by calling {@link Enum#valueOf(Class, String)}. @@ -44,6 +45,7 @@ final class StringToEnumConverterFactory implements ConverterFactory