Skip to content

Commit c65f165

Browse files
committed
Refine NullableUtils deprecations.
See #3305 Original pull request: #3307
1 parent cb6793f commit c65f165

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

src/main/java/org/springframework/data/repository/core/support/MethodInvocationValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
* @author Christoph Strobl
3030
* @since 2.0
3131
* @see org.jspecify.annotations.NonNull
32+
* @see org.springframework.core.Nullness
3233
* @see org.springframework.data.util.ReflectionUtils#isNullable(org.springframework.core.MethodParameter)
33-
* @see org.springframework.data.util.NullableUtils
3434
*/
3535
public class MethodInvocationValidator extends NullnessMethodInvocationValidator {
3636

src/main/java/org/springframework/data/util/NullableUtils.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@
4242
/**
4343
* Utility methods to introspect nullability rules declared in packages, classes and methods.
4444
* <p>
45-
* Nullability rules are declared using {@link NonNullApi}, {@link Nullable}, and JSR-305
45+
* Nullability rules are declared using {@code Nullable}, {@code NonNullApi}, and JSR-305
4646
* {@code javax.annotation.Nonnull} annotations. By default (no annotation use), a package and its types are considered
4747
* allowing {@literal null} values in return values and method parameters. Nullability rules are expressed by annotating
48-
* a package with a JSR-305 meta annotation such as Spring's {@link NonNullApi}. All types of the package inherit the
49-
* package rule. Subpackages do not inherit nullability rules and must be annotated themself.
48+
* a package with a JSR-305 meta annotation such as Spring's {@code NonNullApi}. All types of the package inherit the
49+
* package rule. Subpackages do not inherit nullability rules and must be annotated themselves.
5050
*
5151
* <pre class="code">
5252
* &#64;org.jspecify.annotations.NullMarked
5353
* package com.example;
5454
* </pre>
5555
*
56-
* {@link Nullable} selectively permits {@literal null} values for method return values or method parameters by
56+
* {@code Nullable} selectively permits {@literal null} values for method return values or method parameters by
5757
* annotating the method respectively the parameters:
5858
*
5959
* <pre class="code">
@@ -77,7 +77,10 @@
7777
* @since 2.0
7878
* @see NonNullApi
7979
* @see Nullable
80+
* @deprecated since 4.0 in favor of {@link org.springframework.core.Nullness} fully using JSpecify annotations instead
81+
* of Spring Framework's own {@literal @Nullable} and {@literal @NonNullApi} annotations.
8082
*/
83+
@Deprecated(since = "4.0")
8184
public abstract class NullableUtils {
8285

8386
private static final String NON_NULL_CLASS_NAME = "javax.annotation.Nonnull";

src/main/java/org/springframework/data/util/NullnessMethodInvocationValidator.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
* @author Christoph Strobl
4747
* @since 3.5
4848
* @see org.jspecify.annotations.NonNull
49+
* @see org.springframework.core.Nullness
4950
* @see ReflectionUtils#isNullable(MethodParameter)
50-
* @see NullableUtils
5151
* @link <a href="https://www.thedictionaryofobscuresorrows.com/word/nullness">Nullness</a>
5252
*/
5353
public class NullnessMethodInvocationValidator implements MethodInterceptor {
@@ -63,14 +63,12 @@ public class NullnessMethodInvocationValidator implements MethodInterceptor {
6363
*/
6464
public static boolean supports(Class<?> type) {
6565

66-
if (type.getPackage() != null
67-
&& type.getPackage().isAnnotationPresent(NullMarked.class)) {
66+
if (type.getPackage() != null && type.getPackage().isAnnotationPresent(NullMarked.class)) {
6867
return true;
6968
}
7069

7170
return KotlinDetector.isKotlinPresent() && KotlinReflectionUtils.isSupportedKotlinClass(type)
72-
|| NullableUtils.isNonNull(type, ElementType.METHOD)
73-
|| NullableUtils.isNonNull(type, ElementType.PARAMETER);
71+
|| NullableUtils.isNonNull(type, ElementType.METHOD) || NullableUtils.isNonNull(type, ElementType.PARAMETER);
7472
}
7573

7674
@Override
@@ -195,17 +193,19 @@ private static boolean isNullableParameter(MethodParameter parameter) {
195193

196194
/**
197195
* Check method return nullability
196+
*
198197
* @param method
199198
* @return
200199
*/
201200
private static boolean allowNullableReturn(@Nullable Method method) {
202201

203-
if(method == null) {
202+
if (method == null) {
204203
return false;
205204
}
206205

207-
KFunction<?> function = KotlinDetector.isKotlinType(method.getDeclaringClass()) ?
208-
KotlinReflectionUtils.findKotlinFunction(method) : null;
206+
KFunction<?> function = KotlinDetector.isKotlinType(method.getDeclaringClass())
207+
? KotlinReflectionUtils.findKotlinFunction(method)
208+
: null;
209209
return function != null && function.getReturnType().isMarkedNullable();
210210
}
211211

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* Support for Kotlin Coroutines repositories.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.data.repository.kotlin;

0 commit comments

Comments
 (0)