Skip to content

Commit cf90bee

Browse files
committed
Refine null-safety in the spring-core module
Closes gh-34150
1 parent fbc7590 commit cf90bee

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

spring-core-test/src/main/java/org/springframework/aot/agent/InstrumentedMethod.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,14 @@ enum InstrumentedMethod {
173173
/**
174174
* {@link Class#getField(String)}.
175175
*/
176-
@SuppressWarnings("NullAway")
177176
CLASS_GETFIELD(Class.class, "getField", HintType.REFLECTION,
178177
invocation -> {
179178
Field field = invocation.getReturnValue();
180179
if (field == null) {
181180
return runtimeHints -> false;
182181
}
183182
return reflection().onType(field.getDeclaringClass())
184-
.or(reflection().onField(invocation.getReturnValue()));
183+
.or(reflection().onField(field));
185184
}),
186185

187186
/**

spring-core/src/main/java/org/springframework/util/ClassUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ public static boolean isPrimitiveWrapperArray(Class<?> clazz) {
558558
* @param clazz the class to check
559559
* @return the original class, or a primitive wrapper for the original primitive type
560560
*/
561-
@SuppressWarnings("NullAway")
561+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
562562
public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
563563
Assert.notNull(clazz, "Class must not be null");
564564
return (clazz.isPrimitive() && clazz != void.class ? primitiveTypeToWrapperMap.get(clazz) : clazz);

spring-core/src/main/java/org/springframework/util/InvalidMimeTypeException.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,12 +16,15 @@
1616

1717
package org.springframework.util;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
/**
2022
* Exception thrown from {@link MimeTypeUtils#parseMimeType(String)} in case of
2123
* encountering an invalid content type specification String.
2224
*
2325
* @author Juergen Hoeller
2426
* @author Rossen Stoyanchev
27+
* @author Sebastien Deleuze
2528
* @since 4.0
2629
*/
2730
@SuppressWarnings("serial")
@@ -35,8 +38,10 @@ public class InvalidMimeTypeException extends IllegalArgumentException {
3538
* @param mimeType the offending media type
3639
* @param message a detail message indicating the invalid part
3740
*/
38-
public InvalidMimeTypeException(String mimeType, String message) {
39-
super("Invalid mime type \"" + mimeType + "\": " + message);
41+
public InvalidMimeTypeException(String mimeType, @Nullable String message) {
42+
super(message == null ?
43+
"Invalid mime type \"" + mimeType + "\"" :
44+
"Invalid mime type \"" + mimeType + "\": " + message);
4045
this.mimeType = mimeType;
4146
}
4247

spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java

-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ public static MimeType parseMimeType(String mimeType) {
203203
return cachedMimeTypes.get(mimeType);
204204
}
205205

206-
@SuppressWarnings("NullAway")
207206
private static MimeType parseMimeTypeInternal(String mimeType) {
208207
int index = mimeType.indexOf(';');
209208
String fullType = (index >= 0 ? mimeType.substring(0, index) : mimeType).trim();

spring-core/src/main/java/org/springframework/util/NumberUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ else if (BigDecimal.class == targetClass || Number.class == targetClass) {
236236
* @see #convertNumberToTargetClass
237237
* @see #parseNumber(String, Class)
238238
*/
239-
@SuppressWarnings("NullAway")
239+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
240240
public static <T extends Number> T parseNumber(
241241
String text, Class<T> targetClass, @Nullable NumberFormat numberFormat) {
242242

0 commit comments

Comments
 (0)