Skip to content

Commit d5a8615

Browse files
committed
Support jspecify @nullable in configuration metadata processor and tests
- Switch tests to org.jspecify.annotations.Nullable and remove local org.springframework.lang.Nullable - Recognize both org.springframework.lang.Nullable and org.jspecify.annotations.Nullable as optional in the processor (backward compatible) - Add org.jspecify:jspecify as testCompileOnly (no runtime impact) Signed-off-by: wonyongg <[email protected]>
1 parent 9cdbf91 commit d5a8615

File tree

4 files changed

+11
-38
lines changed

4 files changed

+11
-38
lines changed

configuration-metadata/spring-boot-configuration-processor/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ architectureCheck {
3636

3737
dependencies {
3838
testCompileOnly("com.google.code.findbugs:jsr305:3.0.2")
39+
testCompileOnly("org.jspecify:jspecify")
3940

4041
testImplementation(enforcedPlatform(project(":platform:spring-boot-dependencies")))
4142
testImplementation(project(":test-support:spring-boot-test-support"))

configuration-metadata/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataGenerationEnvironment.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656
*/
5757
class MetadataGenerationEnvironment {
5858

59-
private static final String NULLABLE_ANNOTATION = "org.springframework.lang.Nullable";
59+
private static final Set<String> NULLABLE_ANNOTATIONS = Set.of(
60+
"org.springframework.lang.Nullable",
61+
"org.jspecify.annotations.Nullable");
6062

6163
private static final Set<String> TYPE_EXCLUDES = Set.of("com.zaxxer.hikari.IConnectionCustomizer",
6264
"groovy.lang.MetaClass", "groovy.text.markup.MarkupTemplateEngine", "java.io.Writer", "java.io.PrintWriter",
@@ -375,7 +377,12 @@ AnnotationMirror getNameAnnotation(Element element) {
375377
}
376378

377379
boolean hasNullableAnnotation(Element element) {
378-
return getAnnotation(element, NULLABLE_ANNOTATION) != null;
380+
for (String nullableAnnotation : NULLABLE_ANNOTATIONS) {
381+
if (getAnnotation(element, nullableAnnotation) != null) {
382+
return true;
383+
}
384+
}
385+
return false;
379386
}
380387

381388
boolean hasOptionalParameterAnnotation(Element element) {

configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/NullableParameterEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import org.springframework.boot.configurationsample.Endpoint;
2020
import org.springframework.boot.configurationsample.ReadOperation;
21-
import org.springframework.lang.Nullable;
21+
import org.jspecify.annotations.Nullable;
2222

2323
/**
2424
* An endpoint with @Nullable parameter to test.

configuration-metadata/spring-boot-configuration-processor/src/test/java/org/springframework/lang/Nullable.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)