From 346b9b089385b24a686054890d7831901ed48087 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 16 Dec 2024 21:04:39 -0800 Subject: [PATCH] Fix crash with annotation on enum (#1097) Fixes #1093 We just missed a case. --- .../com/uber/nullaway/NullabilityUtil.java | 6 ++++-- .../uber/nullaway/jspecify/GenericsTests.java | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java b/nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java index 4df2807189..5ffc0454fd 100644 --- a/nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java +++ b/nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java @@ -367,8 +367,10 @@ private static boolean targetTypeMatches(Symbol sym, TypeAnnotationPosition posi return false; } case CLASS: - // There are no type annotations on the top-level type of the class being declared, only - // on other types in the signature (e.g. `class Foo extends Bar<@A Baz> {}`). + // treated like a class + case ENUM: + // There are no type annotations on the top-level type of the class/enum being declared, + // only on other types in the signature (e.g. `class Foo extends Bar<@A Baz> {}`). return false; default: // Compare with toString() to preserve compatibility with JDK 11 diff --git a/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java b/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java index 946b6963c4..7585c85657 100644 --- a/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java @@ -2027,6 +2027,24 @@ public void issue1082() { .doTest(); } + @Test + public void issue1093() { + makeHelper() + .addSourceLines( + "Main.java", + "package com.uber;", + "import org.jspecify.annotations.Nullable;", + "public class Main {", + " interface CacheLoader {", + " }", + " enum Loader implements CacheLoader<@Nullable Integer> {", + " NULL;", + " Loader() {}", + " }", + "}") + .doTest(); + } + private CompilationTestHelper makeHelper() { return makeTestHelperWithArgs( Arrays.asList(