Improve null-safety to fix some Spring Boot warnings

Issue: SPR-15540
This commit is contained in:
Sebastien Deleuze
2017-05-31 16:55:57 +02:00
parent b47d713e14
commit c3e6afb879
19 changed files with 59 additions and 46 deletions

View File

@@ -231,7 +231,7 @@ public abstract class AnnotationUtils {
* @see AnnotatedElement#getAnnotations()
*/
@Nullable
public static Annotation[] getAnnotations(AnnotatedElement annotatedElement) {
public static Annotation[] getAnnotations(@Nullable AnnotatedElement annotatedElement) {
try {
return synthesizeAnnotationArray(annotatedElement.getAnnotations(), annotatedElement);
}
@@ -1441,7 +1441,7 @@ public abstract class AnnotationUtils {
}
@SuppressWarnings("unchecked")
static <A extends Annotation> A synthesizeAnnotation(A annotation, Object annotatedElement) {
static <A extends Annotation> A synthesizeAnnotation(A annotation, @Nullable Object annotatedElement) {
if (annotation == null) {
return null;
}
@@ -1548,8 +1548,7 @@ public abstract class AnnotationUtils {
* @see #synthesizeAnnotation(Annotation, AnnotatedElement)
* @see #synthesizeAnnotation(Map, Class, AnnotatedElement)
*/
@Nullable
static Annotation[] synthesizeAnnotationArray(@Nullable Annotation[] annotations, @Nullable Object annotatedElement) {
static Annotation[] synthesizeAnnotationArray(Annotation[] annotations, @Nullable Object annotatedElement) {
if (annotations == null) {
return null;
}

View File

@@ -38,7 +38,7 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
* Create a new resolver against the given property sources.
* @param propertySources the set of {@link PropertySource} objects to use
*/
public PropertySourcesPropertyResolver(PropertySources propertySources) {
public PropertySourcesPropertyResolver(@Nullable PropertySources propertySources) {
this.propertySources = propertySources;
}

View File

@@ -18,6 +18,7 @@ import javax.annotation.meta.TypeQualifierDefault;
*
* @author Sebastien Deleuze
* @since 5.0
* @see NonNull
* @see javax.annotation.Nonnull
*/
@Documented

View File

@@ -140,7 +140,8 @@ public abstract class ReflectionUtils {
* @param target the target object from which to get the field
* @return the field's current value
*/
public static Object getField(Field field, Object target) {
@Nullable
public static Object getField(Field field, @Nullable Object target) {
try {
return field.get(target);
}

View File

@@ -978,7 +978,7 @@ public abstract class StringUtils {
* @param array the original {@code String} array
* @return the resulting array (of the same size) with trimmed elements
*/
public static String[] trimArrayElements(String[] array) {
public static String[] trimArrayElements(@Nullable String[] array) {
if (ObjectUtils.isEmpty(array)) {
return new String[0];
}