Skip to content

Support JSpecify for actuator endpoint parameters #46595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public boolean isMandatory() {
@SuppressWarnings("deprecation")
private boolean isOptional() {
return this.parameter.getAnnotationsByType(org.springframework.lang.Nullable.class).length > 0
|| this.parameter.getAnnotatedType().isAnnotationPresent(org.jspecify.annotations.Nullable.class)
|| this.optional.test(this.parameter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class OperationMethodParameterTests {

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

private final Method exampleJSpecifyNullable = ReflectionUtils.findMethod(getClass(), "exampleJSpecifyNullable",
String.class, String.class);

@Test
void getNameShouldReturnName() {
OperationMethodParameter parameter = new OperationMethodParameter("name", this.example.getParameters()[0],
Expand Down Expand Up @@ -126,6 +129,13 @@ void getAnnotationShouldReturnAnnotation() {
assertThat(annotation.match()).isEqualTo(Match.ALL_REMAINING);
}

@Test
void isMandatoryWhenJSpecifyNullableAnnotationShouldReturnFalse() {
OperationMethodParameter parameter = new OperationMethodParameter("name",
this.exampleJSpecifyNullable.getParameters()[1], this::isOptionalParameter);
assertThat(parameter.isMandatory()).isFalse();
}

private boolean isOptionalParameter(Parameter parameter) {
return MergedAnnotations.from(parameter).isPresent(TestOptional.class);
}
Expand All @@ -149,6 +159,9 @@ void exampleJsr305NonNull(String one, @javax.annotation.Nonnull String two) {
void exampleAnnotation(@Selector(match = Match.ALL_REMAINING) String allRemaining) {
}

void exampleJSpecifyNullable(String one, @org.jspecify.annotations.Nullable String two) {
}

@TypeQualifier
@Retention(RetentionPolicy.RUNTIME)
@Nonnull(when = When.MAYBE)
Expand Down