From e65e2ce730c3e5a6e2723ea87c8a7a5c144a607f Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sun, 28 Jan 2024 13:25:04 +0100 Subject: [PATCH] Prevent `ExplicitEnumOrdering` from throwing an NPE (#998) --- .../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 37fb7d6086..1320503146 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 7afdf30ac3..02f770ff94 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();