Refine null-safety in the spring-core module

Closes gh-34150
This commit is contained in:
Sébastien Deleuze 2024-12-24 16:46:00 +01:00
parent fbc759077c
commit cf90beec0a
5 changed files with 11 additions and 8 deletions

View File

@ -173,7 +173,6 @@ enum InstrumentedMethod {
/**
* {@link Class#getField(String)}.
*/
@SuppressWarnings("NullAway")
CLASS_GETFIELD(Class.class, "getField", HintType.REFLECTION,
invocation -> {
Field field = invocation.getReturnValue();
@ -181,7 +180,7 @@ enum InstrumentedMethod {
return runtimeHints -> false;
}
return reflection().onType(field.getDeclaringClass())
.or(reflection().onField(invocation.getReturnValue()));
.or(reflection().onField(field));
}),
/**

View File

@ -558,7 +558,7 @@ public abstract class ClassUtils {
* @param clazz the class to check
* @return the original class, or a primitive wrapper for the original primitive type
*/
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null");
return (clazz.isPrimitive() && clazz != void.class ? primitiveTypeToWrapperMap.get(clazz) : clazz);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2024 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.
@ -16,12 +16,15 @@
package org.springframework.util;
import org.jspecify.annotations.Nullable;
/**
* Exception thrown from {@link MimeTypeUtils#parseMimeType(String)} in case of
* encountering an invalid content type specification String.
*
* @author Juergen Hoeller
* @author Rossen Stoyanchev
* @author Sebastien Deleuze
* @since 4.0
*/
@SuppressWarnings("serial")
@ -35,8 +38,10 @@ public class InvalidMimeTypeException extends IllegalArgumentException {
* @param mimeType the offending media type
* @param message a detail message indicating the invalid part
*/
public InvalidMimeTypeException(String mimeType, String message) {
super("Invalid mime type \"" + mimeType + "\": " + message);
public InvalidMimeTypeException(String mimeType, @Nullable String message) {
super(message == null ?
"Invalid mime type \"" + mimeType + "\"" :
"Invalid mime type \"" + mimeType + "\": " + message);
this.mimeType = mimeType;
}

View File

@ -203,7 +203,6 @@ public abstract class MimeTypeUtils {
return cachedMimeTypes.get(mimeType);
}
@SuppressWarnings("NullAway")
private static MimeType parseMimeTypeInternal(String mimeType) {
int index = mimeType.indexOf(';');
String fullType = (index >= 0 ? mimeType.substring(0, index) : mimeType).trim();

View File

@ -236,7 +236,7 @@ public abstract class NumberUtils {
* @see #convertNumberToTargetClass
* @see #parseNumber(String, Class)
*/
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
public static <T extends Number> T parseNumber(
String text, Class<T> targetClass, @Nullable NumberFormat numberFormat) {