Skip to content

Commit 35fede1

Browse files
committed
Polish Nullness
1 parent 564eb77 commit 35fede1

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

spring-core/src/main/java/org/springframework/core/Nullness.java

+20-13
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,29 @@
3737
import org.jspecify.annotations.Nullable;
3838

3939
/**
40-
* Constants that indicate the nullness, as well as related utility methods.
40+
* Constants that indicate nullness, as well as related utility methods.
4141
*
42-
* <p>The nullness applies to a type usage, a field, a method return type or a parameter.
43-
* <a href="https://jspecify.dev/docs/user-guide/">JSpecify annotations</a> are fully supported, as well as
44-
* <a href="https://kotlinlang.org/docs/null-safety.html">Kotlin null safety</a>, {@code @Nullable} annotations
45-
* regardless of their package and Java primitive types.
42+
* <p>Nullness applies to type usage, a field, a method return type, or a parameter.
43+
* <a href="https://jspecify.dev/docs/user-guide/">JSpecify annotations</a> are
44+
* fully supported, as well as
45+
* <a href="https://kotlinlang.org/docs/null-safety.html">Kotlin null safety</a>,
46+
* {@code @Nullable} annotations regardless of their package, and Java primitive
47+
* types.
4648
*
47-
* <p>JSR-305 annotations as well as Spring ones in the {@code org.springframework.lang} packages such as
48-
* {@code @NonNullApi}, {@code @NonNullFields} and {@code @NonNull} are not supported by this API, except
49-
* {@code @Nullable} which is supported via the package-less check. Migrating to JSpecify is recommended.
49+
* <p>JSR-305 annotations as well as Spring null safety annotations in the
50+
* {@code org.springframework.lang} package such as {@code @NonNullApi},
51+
* {@code @NonNullFields}, and {@code @NonNull} are not supported by this API.
52+
* However, {@code @Nullable} is supported via the package-less check. Migrating
53+
* to JSpecify is recommended.
5054
*
5155
* @author Sebastien Deleuze
5256
* @since 7.0
5357
*/
5458
public enum Nullness {
5559

5660
/**
57-
* Unspecified nullness (Java default for non-primitive types and JSpecify {@code @NullUnmarked} code).
61+
* Unspecified nullness (Java default for non-primitive types and JSpecify
62+
* {@code @NullUnmarked} code).
5863
*/
5964
UNSPECIFIED,
6065

@@ -70,7 +75,7 @@ public enum Nullness {
7075

7176

7277
/**
73-
* Return the nullness of the given method return type.
78+
* Return the nullness of the return type for the given method.
7479
* @param method the source for the method return type
7580
* @return the corresponding nullness
7681
*/
@@ -123,7 +128,8 @@ public static Nullness forField(Field field) {
123128
}
124129

125130

126-
// Check method and parameter level @Nullable annotations regardless of the package (including Spring and JSR 305 annotations)
131+
// Check method and parameter level @Nullable annotations regardless of the package
132+
// (including Spring and JSR 305 annotations)
127133
private static boolean hasNullableAnnotation(AnnotatedElement element) {
128134
for (Annotation annotation : element.getDeclaredAnnotations()) {
129135
if ("Nullable".equals(annotation.annotationType().getSimpleName())) {
@@ -133,7 +139,9 @@ private static boolean hasNullableAnnotation(AnnotatedElement element) {
133139
return false;
134140
}
135141

136-
private static Nullness jSpecifyNullness(AnnotatedElement annotatedElement, Class<?> declaringClass, AnnotatedType annotatedType) {
142+
private static Nullness jSpecifyNullness(
143+
AnnotatedElement annotatedElement, Class<?> declaringClass, AnnotatedType annotatedType) {
144+
137145
if (annotatedType.getType() instanceof Class<?> clazz && clazz.isPrimitive()) {
138146
return (clazz != void.class ? Nullness.NON_NULL : Nullness.UNSPECIFIED);
139147
}
@@ -171,7 +179,6 @@ else if (annotatedElement.isAnnotationPresent(NullUnmarked.class)) {
171179
*/
172180
private static class KotlinDelegate {
173181

174-
175182
public static Nullness forMethodReturnType(Method method) {
176183
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
177184
if (function != null && function.getReturnType().isMarkedNullable()) {

0 commit comments

Comments
 (0)