From 02b63a42a3012f1443c0509f8fcaf8feabbcb454 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sat, 27 Jan 2024 12:11:51 +0100 Subject: [PATCH] Prevent `ExplicitEnumOrdering` from throwing an NPE --- .../picnic/errorprone/bugpatterns/ExplicitEnumOrdering.java | 2 +- .../picnic/errorprone/bugpatterns/ExplicitEnumOrderingTest.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrdering.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrdering.java index 37fb7d60860..13205031468 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrdering.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrdering.java @@ -72,7 +72,7 @@ private static ImmutableSet getMissingEnumValues( List expressions) { return expressions.stream() .map(ASTHelpers::getSymbol) - .filter(Symbol::isEnum) + .filter(s -> s != null && s.isEnum()) .collect( collectingAndThen( toImmutableSetMultimap(Symbol::asType, Symbol::toString), diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrderingTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrderingTest.java index 7afdf30ac3a..02f770ff94f 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrderingTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrderingTest.java @@ -75,6 +75,8 @@ void identification() { " Ordering.explicit(IsoEra.BCE, SOURCE, RetentionPolicy.CLASS);", " // BUG: Diagnostic contains: RetentionPolicy.SOURCE, IsoEra.BCE", " Ordering.explicit(CLASS, RUNTIME, CE);", + "", + " Ordering.explicit(BCE, null, CE);", " }", "}") .doTest();