From 84e7fa4cb976d8ce3a110ce2ac9960c26ab494a5 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sat, 21 Sep 2024 16:52:57 +0200 Subject: [PATCH] Have `LexicographicalAnnotationAttributeListing` also sort booleans and chars --- ...cographicalAnnotationAttributeListing.java | 7 ++- ...aphicalAnnotationAttributeListingTest.java | 54 ++++++++++++++++++- .../utils/ThirdPartyLibraryTest.java | 2 +- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java index 62577e94cca..fca196b4647 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java @@ -163,7 +163,12 @@ private static boolean canSort(Tree array, VisitorState state) { /* For now we don't force sorting on numeric types. */ return Stream.of( - symtab.annotationType, symtab.classType, symtab.enumSym.type, symtab.stringType) + symtab.annotationType, + symtab.booleanType, + symtab.charType, + symtab.classType, + symtab.enumSym.type, + symtab.stringType) .anyMatch(t -> ASTHelpers.isSubtype(elemType, t, state)); } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListingTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListingTest.java index da842fd92a8..b73458a5e39 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListingTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListingTest.java @@ -29,6 +29,10 @@ void identification() { " @interface Foo {", " String[] value() default {};", "", + " boolean[] bools() default {};", + "", + " char[] chars() default {};", + "", " int[] ints() default {};", "", " Class[] cls() default {};", @@ -69,6 +73,32 @@ void identification() { " @Foo({\"a\", \"A\"})", " A unsortedStringCaseInsensitiveWithTotalOrderFallback();", "", + " @Foo(bools = {})", + " A noBools();", + "", + " @Foo(bools = {false})", + " A oneBool();", + "", + " @Foo(bools = {false, true})", + " A sortedBools();", + "", + " // BUG: Diagnostic contains:", + " @Foo(bools = {true, false})", + " A unsortedBools();", + "", + " @Foo(chars = {})", + " A noChars();", + "", + " @Foo(chars = {'a'})", + " A oneChar();", + "", + " @Foo(chars = {'a', 'b'})", + " A sortedChars();", + "", + " // BUG: Diagnostic contains:", + " @Foo(chars = {'b', 'a'})", + " A unsortedChars();", + "", " @Foo(ints = {})", " A noInts();", "", @@ -173,6 +203,10 @@ LexicographicalAnnotationAttributeListing.class, getClass()) " @interface Foo {", " String[] value() default {};", "", + " boolean[] bools() default {};", + "", + " char[] chars() default {};", + "", " Class[] cls() default {};", "", " RoundingMode[] enums() default {};", @@ -185,7 +219,13 @@ LexicographicalAnnotationAttributeListing.class, getClass()) " }", "", " @Foo({\" \", \"\", \"b\", \"a\"})", - " A unsortedString();", + " A unsortedStrings();", + "", + " @Foo(bools = {true, false})", + " A unsortedBooleans();", + "", + " @Foo(chars = {'b', 'a'})", + " A unsortedChars();", "", " @Foo(cls = {long.class, int.class})", " A unsortedClasses();", @@ -210,6 +250,10 @@ LexicographicalAnnotationAttributeListing.class, getClass()) " @interface Foo {", " String[] value() default {};", "", + " boolean[] bools() default {};", + "", + " char[] chars() default {};", + "", " Class[] cls() default {};", "", " RoundingMode[] enums() default {};", @@ -222,7 +266,13 @@ LexicographicalAnnotationAttributeListing.class, getClass()) " }", "", " @Foo({\"\", \" \", \"a\", \"b\"})", - " A unsortedString();", + " A unsortedStrings();", + "", + " @Foo(bools = {false, true})", + " A unsortedBooleans();", + "", + " @Foo(chars = {'a', 'b'})", + " A unsortedChars();", "", " @Foo(cls = {int.class, long.class})", " A unsortedClasses();", diff --git a/error-prone-utils/src/test/java/tech/picnic/errorprone/utils/ThirdPartyLibraryTest.java b/error-prone-utils/src/test/java/tech/picnic/errorprone/utils/ThirdPartyLibraryTest.java index ac713c55894..06bfd5c5f4f 100644 --- a/error-prone-utils/src/test/java/tech/picnic/errorprone/utils/ThirdPartyLibraryTest.java +++ b/error-prone-utils/src/test/java/tech/picnic/errorprone/utils/ThirdPartyLibraryTest.java @@ -73,7 +73,7 @@ void isIntroductionAllowedWitnessClassesNotOnClassPath() { } @ParameterizedTest - @ValueSource(booleans = {true, false}) + @ValueSource(booleans = {false, true}) void isIntroductionAllowedIgnoreClasspathCompat(boolean ignoreClassPath) { CompilationTestHelper.newInstance(IsIntroductionAllowedTestChecker.class, getClass()) .setArgs("-XepOpt:ErrorProneSupport:IgnoreClasspathCompat=" + ignoreClassPath)