Skip to content
Closed
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