Skip to content

Commit cc04337

Browse files
Support JSpecify for actuator endpoint parameters
1 parent f5dcf51 commit cc04337

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public boolean isMandatory() {
8080
@SuppressWarnings("deprecation")
8181
private boolean isOptional() {
8282
return this.parameter.getAnnotationsByType(org.springframework.lang.Nullable.class).length > 0
83+
|| this.parameter.getAnnotatedType().isAnnotationPresent(org.jspecify.annotations.Nullable.class)
8384
|| this.optional.test(this.parameter);
8485
}
8586

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class OperationMethodParameterTests {
6161

6262
private Method exampleAnnotation = ReflectionUtils.findMethod(getClass(), "exampleAnnotation", String.class);
6363

64+
private final Method exampleJSpecifyNullable = ReflectionUtils.findMethod(getClass(), "exampleJSpecifyNullable",
65+
String.class, String.class);
66+
6467
@Test
6568
void getNameShouldReturnName() {
6669
OperationMethodParameter parameter = new OperationMethodParameter("name", this.example.getParameters()[0],
@@ -126,6 +129,13 @@ void getAnnotationShouldReturnAnnotation() {
126129
assertThat(annotation.match()).isEqualTo(Match.ALL_REMAINING);
127130
}
128131

132+
@Test
133+
void isMandatoryWhenJSpecifyNullableAnnotationShouldReturnFalse() {
134+
OperationMethodParameter parameter = new OperationMethodParameter("name",
135+
this.exampleJSpecifyNullable.getParameters()[1], this::isOptionalParameter);
136+
assertThat(parameter.isMandatory()).isFalse();
137+
}
138+
129139
private boolean isOptionalParameter(Parameter parameter) {
130140
return MergedAnnotations.from(parameter).isPresent(TestOptional.class);
131141
}
@@ -149,6 +159,9 @@ void exampleJsr305NonNull(String one, @javax.annotation.Nonnull String two) {
149159
void exampleAnnotation(@Selector(match = Match.ALL_REMAINING) String allRemaining) {
150160
}
151161

162+
void exampleJSpecifyNullable(String one, @org.jspecify.annotations.Nullable String two) {
163+
}
164+
152165
@TypeQualifier
153166
@Retention(RetentionPolicy.RUNTIME)
154167
@Nonnull(when = When.MAYBE)

0 commit comments

Comments
 (0)