Skip to content

Commit ec06257

Browse files
committed
Remove Jakarta annotation support.
1 parent 33dbc9a commit ec06257

File tree

7 files changed

+5
-165
lines changed

7 files changed

+5
-165
lines changed

pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<scala>2.11.7</scala>
3636
<xmlbeam>1.4.24</xmlbeam>
3737
<java-module-name>spring.data.commons</java-module-name>
38-
<jakarta-annotation-api>2.1.1</jakarta-annotation-api>
3938
<kotlin.api.target>1.8</kotlin.api.target>
4039
</properties>
4140

src/main/java/org/springframework/data/util/Nullability.java

-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@
7272
* <ul>
7373
* <li>Spring's {@link NonNullApi}, {@link Nullable}, and {@link org.springframework.lang.NonNull}.</li>
7474
* <li>JSR-305 {@code javax.annotation.Nonnull} and meta-annotations.</li>
75-
* <li><a href="https://projects.eclipse.org/projects/ee4j.ca">Jakarta Annotations API</a> via
76-
* {@code jakarta.annotation.Nonnull} which is a simplified variant of JSR-305 {@code javax.annotation.Nonnull} without
77-
* {@code when} and {@code @TypeQualifierDefault}.</li>
7875
* <li><a href="https://https://jspecify.dev/">JSpecify</a>, a newly designed specification to opt-in for non-null by
7976
* default through {@code org.jspecify.annotations.NullMarked} and {@code org.jspecify.annotations.Nullable}.</li>
8077
* </ul>

src/main/java/org/springframework/data/util/NullabilityIntrospector.java

+4-61
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,14 @@ class NullabilityIntrospector implements Nullability.Introspector {
5353
private static final List<NullabilityProvider> providers;
5454

5555
static {
56-
providers = new ArrayList<>(5);
56+
providers = new ArrayList<>(4);
5757

5858
providers.add(new PrimitiveProvider());
5959

6060
if (Jsr305Provider.isAvailable()) {
6161
providers.add(new Jsr305Provider());
6262
}
6363

64-
if (JakartaAnnotationProvider.isAvailable()) {
65-
providers.add(new JakartaAnnotationProvider());
66-
}
67-
6864
if (JSpecifyAnnotationProvider.isAvailable()) {
6965
providers.add(new JSpecifyAnnotationProvider());
7066
}
@@ -369,24 +365,6 @@ static boolean isNullable(Annotation annotation) {
369365
}
370366
}
371367

372-
/**
373-
* Simplified variant of {@link Jsr305Provider} without {@code when} and {@code @TypeQualifierDefault} support.
374-
*/
375-
@SuppressWarnings("DataFlowIssue")
376-
static class JakartaAnnotationProvider extends SimpleAnnotationNullabilityProvider {
377-
378-
private static final Class<Annotation> NON_NULL = findClass("jakarta.annotation.Nonnull");
379-
private static final Class<Annotation> NULLABLE = findClass("jakarta.annotation.Nullable");
380-
381-
JakartaAnnotationProvider() {
382-
super(NON_NULL, NULLABLE);
383-
}
384-
385-
public static boolean isAvailable() {
386-
return NON_NULL != null && NULLABLE != null;
387-
}
388-
}
389-
390368
/**
391369
* Provider for JSpecify annotations.
392370
*/
@@ -431,49 +409,15 @@ Spec evaluate(AnnotatedElement element, ElementType elementType) {
431409
private static Spec evaluate(Annotation[] annotations) {
432410
for (Annotation annotation : annotations) {
433411

434-
if (SimpleAnnotationNullabilityProvider.test(NULL_UNMARKED, annotation)) {
412+
if (test(NULL_UNMARKED, annotation)) {
435413
return Spec.UNSPECIFIED;
436414
}
437415

438-
if (SimpleAnnotationNullabilityProvider.test(NULL_MARKED, annotation)
439-
|| SimpleAnnotationNullabilityProvider.test(NON_NULL, annotation)) {
416+
if (test(NULL_MARKED, annotation) || test(NON_NULL, annotation)) {
440417
return Spec.NON_NULL;
441418
}
442419

443-
if (SimpleAnnotationNullabilityProvider.test(NULLABLE, annotation)) {
444-
return Spec.NULLABLE;
445-
}
446-
}
447-
448-
return Spec.UNSPECIFIED;
449-
}
450-
}
451-
452-
/**
453-
* Annotation-based {@link NullabilityProvider} leveraging simple or meta-annotations.
454-
*/
455-
static class SimpleAnnotationNullabilityProvider extends NullabilityProvider {
456-
457-
private final Class<Annotation> nonNull;
458-
private final Class<Annotation> nullable;
459-
460-
SimpleAnnotationNullabilityProvider(Class<Annotation> nonNull, Class<Annotation> nullable) {
461-
this.nonNull = nonNull;
462-
this.nullable = nullable;
463-
}
464-
465-
@Override
466-
Spec evaluate(AnnotatedElement element, ElementType elementType) {
467-
468-
Annotation[] annotations = element.getAnnotations();
469-
470-
for (Annotation annotation : annotations) {
471-
472-
if (test(nonNull, annotation)) {
473-
return Spec.NON_NULL;
474-
}
475-
476-
if (test(nullable, annotation)) {
420+
if (test(NULLABLE, annotation)) {
477421
return Spec.NULLABLE;
478422
}
479423
}
@@ -490,7 +434,6 @@ static boolean test(Class<Annotation> annotationClass, Annotation annotation) {
490434
MergedAnnotations annotations = MergedAnnotations.from(annotation.annotationType());
491435
return annotations.isPresent(annotationClass);
492436
}
493-
494437
}
495438

496439
@Nullable

src/test/java/org/springframework/data/util/NullableUtilsUnitTests.java

+1-46
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,7 @@ void packageAnnotatedShouldConsiderNonNullAnnotationForMethod() {
7070
assertThat(NullableUtils.isNonNull(NonNullOnPackage.class, ElementType.PACKAGE)).isFalse();
7171
}
7272

73-
@Test //
74-
void shouldConsiderJakartaNonNullParameters() {
75-
76-
var method = ReflectionUtils.findMethod(org.springframework.data.util.nonnull.jakarta.NonNullOnPackage.class, "someMethod", String.class, String.class);
77-
Nullability.Introspector introspector = Nullability.introspect(method.getDeclaringClass());
78-
Nullability mrt = introspector.forReturnType(method);
79-
80-
assertThat(mrt.isDeclared()).isTrue();
81-
assertThat(mrt.isNonNull()).isTrue();
82-
assertThat(mrt.isNullable()).isFalse();
83-
84-
Nullability pn0 = introspector.forParameter(MethodParameter.forExecutable(method, 0));
85-
assertThat(pn0.isDeclared()).isTrue();
86-
assertThat(pn0.isNullable()).isFalse();
87-
assertThat(pn0.isNonNull()).isTrue();
88-
89-
Nullability pn1 = introspector.forParameter(MethodParameter.forExecutable(method, 1));
90-
assertThat(pn1.isDeclared()).isTrue();
91-
assertThat(pn1.isNullable()).isTrue();
92-
assertThat(pn1.isNonNull()).isFalse();
93-
}
94-
95-
@Test //
73+
@Test // GH-3100
9674
void shouldConsiderJSpecifyNonNullParameters() {
9775

9876
var method = ReflectionUtils.findMethod(org.springframework.data.util.nonnull.jspecify.NonNullOnPackage.class,
@@ -229,27 +207,4 @@ void shouldConsiderMethodReturnJsr305NonnullAnnotation() {
229207
assertThat(mrt.isNonNull()).isFalse();
230208
}
231209

232-
@Test //
233-
void shouldConsiderMethodReturnJakartaNonnullAnnotation() {
234-
235-
var method = ReflectionUtils.findMethod(NullableAnnotatedType.class, "jakartaNonnullReturnWhen");
236-
237-
Nullability mrt = Nullability.forMethodReturnType(method);
238-
239-
assertThat(mrt.isDeclared()).isTrue();
240-
assertThat(mrt.isNullable()).isFalse();
241-
assertThat(mrt.isNonNull()).isTrue();
242-
}
243-
244-
@Test //
245-
void shouldConsiderMethodReturnJakartaNullableAnnotation() {
246-
247-
var method = ReflectionUtils.findMethod(NullableAnnotatedType.class, "jakartaNullableReturnWhen");
248-
249-
Nullability mrt = Nullability.forMethodReturnType(method);
250-
251-
assertThat(mrt.isDeclared()).isTrue();
252-
assertThat(mrt.isNullable()).isTrue();
253-
assertThat(mrt.isNonNull()).isFalse();
254-
}
255210
}

src/test/java/org/springframework/data/util/nonnull/NullableAnnotatedType.java

-5
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,4 @@ public interface NullableAnnotatedType {
3535
@javax.annotation.Nonnull(when = When.MAYBE)
3636
String jsr305NullableReturnWhen();
3737

38-
@jakarta.annotation.Nonnull
39-
String jakartaNonnullReturnWhen();
40-
41-
@jakarta.annotation.Nullable
42-
String jakartaNullableReturnWhen();
4338
}

src/test/java/org/springframework/data/util/nonnull/jakarta/NonNullOnPackage.java

-26
This file was deleted.

src/test/java/org/springframework/data/util/nonnull/jakarta/package-info.java

-23
This file was deleted.

0 commit comments

Comments
 (0)