diff --git a/pom.xml b/pom.xml index a53fb13..8a8522b 100644 --- a/pom.xml +++ b/pom.xml @@ -86,6 +86,7 @@ 3.0.2 2.15.2 2.13.0 + 2.1.1 3.11.0 3.3.0 @@ -229,6 +230,11 @@ commons-io ${commons-io.version} + + jakarta.annotation + jakarta.annotation-api + ${jakarta.annotation-api.version} + diff --git a/src/main/java/com/societegenerale/commons/plugin/rules/DontReturnNullCollectionTest.java b/src/main/java/com/societegenerale/commons/plugin/rules/DontReturnNullCollectionTest.java index d3ae08f..09bc00d 100644 --- a/src/main/java/com/societegenerale/commons/plugin/rules/DontReturnNullCollectionTest.java +++ b/src/main/java/com/societegenerale/commons/plugin/rules/DontReturnNullCollectionTest.java @@ -24,7 +24,7 @@ */ public class DontReturnNullCollectionTest implements ArchRuleTest { - protected static final String NO_NULL_COLLECTION_MESSAGE = "we don't want callers to perform null check every time. Return an empty collection, not null. Please annotate the method with "+Nonnull.class.getCanonicalName(); + protected static final String NO_NULL_COLLECTION_MESSAGE = "we don't want callers to perform null check every time. Return an empty collection, not null. Please annotate the method with "+Nonnull.class.getCanonicalName()+" or "+ jakarta.annotation.Nonnull.class.getCanonicalName(); @Override public void execute(String packagePath, ScopePathProvider scopePathProvider, Collection excludedPaths) { @@ -33,6 +33,7 @@ public void execute(String packagePath, ScopePathProvider scopePathProvider, Col ArchRule rule = methods().that(returnCollections).and(areNotLambdas) .should().beAnnotatedWith(Nonnull.class) + .orShould().beAnnotatedWith(jakarta.annotation.Nonnull.class) .because(NO_NULL_COLLECTION_MESSAGE) .allowEmptyShould(true); diff --git a/src/test/java/com/societegenerale/aut/main/ObjectWithProperlyAnnotatedMethodsReturningCollections.java b/src/test/java/com/societegenerale/aut/main/ObjectWithProperlyAnnotatedMethodsReturningCollections.java index 6d4a47c..6288f68 100644 --- a/src/test/java/com/societegenerale/aut/main/ObjectWithProperlyAnnotatedMethodsReturningCollections.java +++ b/src/test/java/com/societegenerale/aut/main/ObjectWithProperlyAnnotatedMethodsReturningCollections.java @@ -1,22 +1,30 @@ package com.societegenerale.aut.main; -import javax.annotation.Nonnull; -import java.util.List; -import java.util.Set; - import static java.util.Collections.emptyList; import static java.util.Collections.emptySet; +import java.util.List; +import java.util.Set; + public class ObjectWithProperlyAnnotatedMethodsReturningCollections { - @Nonnull - public List returningANullList(){ + @jakarta.annotation.Nonnull + public List returningANullListWithJakartaNonnullAnnotation(){ return emptyList(); } - @Nonnull - public Set returningANullSet(){ + @jakarta.annotation.Nonnull + public Set returningANullSetWithJakartaNonnullAnnotation(){ return emptySet(); } + @javax.annotation.Nonnull + public List returningANullListWithJavaxNonnullAnnotation(){ + return emptyList(); + } + + @javax.annotation.Nonnull + public Set returningANullSetWithJavaxNonnullAnnotation(){ + return emptySet(); + } }