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 fa92cf5ead8..c3d7051274f 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
@@ -51,6 +51,9 @@
*
The idea behind this checker is that maintaining a sorted sequence simplifies conflict
* resolution, and can even avoid it if two branches add the same entry.
*/
+// XXX: In some places we declare a `@SuppressWarnings` annotation with a final value of
+// `key-to-resolve-AnnotationUseStyle-and-TrailingComment-check-conflict`. That entry must stay
+// last. Consider adding (generic?) support for such cases.
@AutoService(BugChecker.class)
@BugPattern(
summary = "Where possible, sort annotation array attributes lexicographically",
diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java
index bdcffa86615..cd341e791de 100644
--- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java
+++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java
@@ -35,14 +35,21 @@ private CollectionRules() {}
*/
static final class CollectionIsEmpty {
@BeforeTemplate
- @SuppressWarnings("java:S1155" /* This violation will be rewritten. */)
+ @SuppressWarnings({
+ "java:S1155" /* This violation will be rewritten. */,
+ "LexicographicalAnnotationAttributeListing" /* `key-*` entry must remain last. */,
+ "OptionalFirstCollectionElement" /* This is a more specific template. */,
+ "StreamIsEmpty" /* This is a more specific template. */,
+ "key-to-resolve-AnnotationUseStyle-and-TrailingComment-check-conflict"
+ })
boolean before(Collection collection) {
return Refaster.anyOf(
collection.size() == 0,
collection.size() <= 0,
collection.size() < 1,
Iterables.isEmpty(collection),
- collection.stream().findAny().isEmpty());
+ collection.stream().findAny().isEmpty(),
+ collection.stream().findFirst().isEmpty());
}
@BeforeTemplate
@@ -338,7 +345,9 @@ Iterator after(ImmutableCollection collection) {
/**
* Don't use the ternary operator to extract the first element of a possibly-empty {@link
- * Collection} as an {@link Optional}.
+ * Collection} as an {@link Optional}, and (when applicable) prefer {@link Stream#findFirst()}
+ * over {@link Stream#findAny()} to communicate that the collection's first element (if any,
+ * according to iteration order) will be returned.
*/
static final class OptionalFirstCollectionElement {
@BeforeTemplate
diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestInput.java
index 56f194cd4db..186da035b7a 100644
--- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestInput.java
+++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestInput.java
@@ -30,7 +30,8 @@ ImmutableSet testCollectionIsEmpty() {
ImmutableSet.of(6).size() >= 1,
Iterables.isEmpty(ImmutableSet.of(7)),
ImmutableSet.of(8).stream().findAny().isEmpty(),
- ImmutableSet.of(9).asList().isEmpty());
+ ImmutableSet.of(9).stream().findFirst().isEmpty(),
+ ImmutableSet.of(10).asList().isEmpty());
}
ImmutableSet testCollectionSize() {
diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestOutput.java
index 96719dcdbf0..ba09e13e63e 100644
--- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestOutput.java
+++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestOutput.java
@@ -30,7 +30,8 @@ ImmutableSet testCollectionIsEmpty() {
!ImmutableSet.of(6).isEmpty(),
ImmutableSet.of(7).isEmpty(),
ImmutableSet.of(8).isEmpty(),
- ImmutableSet.of(9).isEmpty());
+ ImmutableSet.of(9).isEmpty(),
+ ImmutableSet.of(10).isEmpty());
}
ImmutableSet testCollectionSize() {