diff --git a/nullaway/src/main/java/com/uber/nullaway/generics/CheckIdenticalNullabilityVisitor.java b/nullaway/src/main/java/com/uber/nullaway/generics/CheckIdenticalNullabilityVisitor.java index 5f1bac2742..b0bf30b4ba 100644 --- a/nullaway/src/main/java/com/uber/nullaway/generics/CheckIdenticalNullabilityVisitor.java +++ b/nullaway/src/main/java/com/uber/nullaway/generics/CheckIdenticalNullabilityVisitor.java @@ -35,10 +35,10 @@ public Boolean visitClassType(Type.ClassType lhsType, Type rhsType) { // The base type of rhsType may be a subtype of lhsType's base type. In such cases, we must // compare lhsType against the supertype of rhsType with a matching base type. Type rhsTypeAsSuper = types.asSuper(rhsType, lhsType.tsym); - // This is impossible, considering the fact that standard Java subtyping succeeds before - // running NullAway if (rhsTypeAsSuper == null) { - throw new RuntimeException("Did not find supertype of " + rhsType + " matching " + lhsType); + // Surprisingly, this can in fact occur, in cases involving raw types. See, e.g., + // GenericsTests#issue1082. Bail out. + return true; } // bail out of checking raw types for now if (rhsTypeAsSuper.isRaw()) { 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 bbf4140a4d..7acec2c1da 100644 --- a/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java @@ -2016,11 +2016,13 @@ public void issue1082() { " public interface Expiry {}", " static class Config {", " Config setFactory(Optional>> factory) {", + " // BUG: Diagnostic contains: returning @Nullable expression from method", " return null;", " }", " }", " static void caller(Config config) {", - " config.setFactory(Optional.empty());", + " // checking that we don't crash", + " config.setFactory(Optional.empty());", " }", "}") .doTest();