Skip to content

Commit f00dc97

Browse files
committed
Drop support for javax.annotation.NonNull
Closes gh-46773
1 parent 8d598f5 commit f00dc97

File tree

3 files changed

+3
-76
lines changed

3 files changed

+3
-76
lines changed

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/endpoints.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ Operations on an endpoint receive input through their parameters.
413413
When exposed over the web, the values for these parameters are taken from the URL's query parameters and from the JSON request body.
414414
When exposed over JMX, the parameters are mapped to the parameters of the MBean's operations.
415415
Parameters are required by default.
416-
They can be made optional by annotating them with either `@javax.annotation.Nullable` or javadoc:org.springframework.lang.Nullable[format=annotation].
416+
They can be made optional by annotating them with either javadoc:org.springframework.boot.actuate.endpoint.annotation.OptionalParameter[format=annotation] or javadoc:org.springframework.lang.Nullable[format=annotation].
417417

418418
You can map each root property in the JSON request body to a parameter of the endpoint.
419419
Consider the following JSON request body:
@@ -547,7 +547,7 @@ NOTE: Range requests are not supported when using Jersey.
547547
==== Web Endpoint Security
548548

549549
An operation on a web endpoint or a web-specific endpoint extension can receive the current javadoc:java.security.Principal[] or javadoc:org.springframework.boot.actuate.endpoint.SecurityContext[] as a method parameter.
550-
The former is typically used in conjunction with either `@javax.annotation.Nullable` or javadoc:org.springframework.lang.Nullable[format=annotation] to provide different behavior for authenticated and unauthenticated users.
550+
The former is typically used in conjunction with either javadoc:org.springframework.boot.actuate.endpoint.annotation.OptionalParameter[format=annotation] or javadoc:org.springframework.lang.Nullable[format=annotation] to provide different behavior for authenticated and unauthenticated users.
551551
The latter is typically used to perform authorization checks by using its `isUserInRole(String)` method.
552552

553553

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/invoke/reflect/OperationMethodParameter.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@
2020
import java.lang.reflect.Parameter;
2121
import java.util.function.Predicate;
2222

23-
import javax.annotation.Nonnull;
24-
import javax.annotation.meta.When;
25-
2623
import org.springframework.boot.actuate.endpoint.invoke.OperationParameter;
27-
import org.springframework.core.annotation.MergedAnnotation;
28-
import org.springframework.core.annotation.MergedAnnotations;
29-
import org.springframework.util.ClassUtils;
3024

3125
/**
3226
* {@link OperationParameter} created from an {@link OperationMethod}.
@@ -36,8 +30,6 @@
3630
*/
3731
class OperationMethodParameter implements OperationParameter {
3832

39-
private static final boolean jsr305Present = ClassUtils.isPresent("javax.annotation.Nonnull", null);
40-
4133
private final String name;
4234

4335
private final Parameter parameter;
@@ -68,13 +60,7 @@ public Class<?> getType() {
6860

6961
@Override
7062
public boolean isMandatory() {
71-
if (isOptional()) {
72-
return false;
73-
}
74-
if (jsr305Present) {
75-
return new Jsr305().isMandatory(this.parameter);
76-
}
77-
return true;
63+
return !isOptional();
7864
}
7965

8066
@SuppressWarnings("deprecation")
@@ -93,13 +79,4 @@ public String toString() {
9379
return this.name + " of type " + this.parameter.getType().getName();
9480
}
9581

96-
private static final class Jsr305 {
97-
98-
boolean isMandatory(Parameter parameter) {
99-
MergedAnnotation<Nonnull> annotation = MergedAnnotations.from(parameter).get(Nonnull.class);
100-
return !annotation.isPresent() || annotation.getEnum("when", When.class) == When.ALWAYS;
101-
}
102-
103-
}
104-
10582
}

module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoke/reflect/OperationMethodParameterTests.java

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
import java.lang.reflect.Method;
2525
import java.lang.reflect.Parameter;
2626

27-
import javax.annotation.Nonnull;
28-
import javax.annotation.meta.TypeQualifier;
29-
import javax.annotation.meta.When;
30-
3127
import org.junit.jupiter.api.Test;
3228

3329
import org.springframework.boot.actuate.endpoint.annotation.Selector;
@@ -50,15 +46,6 @@ class OperationMethodParameterTests {
5046
private final Method exampleSpringNullable = ReflectionUtils.findMethod(getClass(), "exampleSpringNullable",
5147
String.class, String.class);
5248

53-
private final Method exampleJsr305 = ReflectionUtils.findMethod(getClass(), "exampleJsr305", String.class,
54-
String.class);
55-
56-
private final Method exampleMetaJsr305 = ReflectionUtils.findMethod(getClass(), "exampleMetaJsr305", String.class,
57-
String.class);
58-
59-
private final Method exampleJsr305NonNull = ReflectionUtils.findMethod(getClass(), "exampleJsr305NonNull",
60-
String.class, String.class);
61-
6249
private Method exampleAnnotation = ReflectionUtils.findMethod(getClass(), "exampleAnnotation", String.class);
6350

6451
@Test
@@ -96,27 +83,6 @@ void isMandatoryWhenSpringNullableAnnotationShouldReturnFalse() {
9683
assertThat(parameter.isMandatory()).isFalse();
9784
}
9885

99-
@Test
100-
void isMandatoryWhenJsrNullableAnnotationShouldReturnFalse() {
101-
OperationMethodParameter parameter = new OperationMethodParameter("name", this.exampleJsr305.getParameters()[1],
102-
this::isOptionalParameter);
103-
assertThat(parameter.isMandatory()).isFalse();
104-
}
105-
106-
@Test
107-
void isMandatoryWhenJsrMetaNullableAnnotationShouldReturnFalse() {
108-
OperationMethodParameter parameter = new OperationMethodParameter("name",
109-
this.exampleMetaJsr305.getParameters()[1], this::isOptionalParameter);
110-
assertThat(parameter.isMandatory()).isFalse();
111-
}
112-
113-
@Test
114-
void isMandatoryWhenJsrNonnullAnnotationShouldReturnTrue() {
115-
OperationMethodParameter parameter = new OperationMethodParameter("name",
116-
this.exampleJsr305NonNull.getParameters()[1], this::isOptionalParameter);
117-
assertThat(parameter.isMandatory()).isTrue();
118-
}
119-
12086
@Test
12187
void getAnnotationShouldReturnAnnotation() {
12288
OperationMethodParameter parameter = new OperationMethodParameter("name",
@@ -137,25 +103,9 @@ void example(String one, @TestOptional String two) {
137103
void exampleSpringNullable(String one, @org.springframework.lang.Nullable String two) {
138104
}
139105

140-
void exampleJsr305(String one, @javax.annotation.Nullable String two) {
141-
}
142-
143-
void exampleMetaJsr305(String one, @MetaNullable String two) {
144-
}
145-
146-
void exampleJsr305NonNull(String one, @javax.annotation.Nonnull String two) {
147-
}
148-
149106
void exampleAnnotation(@Selector(match = Match.ALL_REMAINING) String allRemaining) {
150107
}
151108

152-
@TypeQualifier
153-
@Retention(RetentionPolicy.RUNTIME)
154-
@Nonnull(when = When.MAYBE)
155-
@interface MetaNullable {
156-
157-
}
158-
159109
@Target({ ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD })
160110
@Retention(RetentionPolicy.RUNTIME)
161111
@Documented

0 commit comments

Comments
 (0)