Skip to content

Commit

Permalink
Fix another JSpecify mode crash involving raw types (#1086)
Browse files Browse the repository at this point in the history
Fixes the second crash of #1082. Weird things can happen with raw
types...see the test case.
  • Loading branch information
msridhar authored Dec 12, 2024
1 parent d21d4ab commit 933b1af
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 and https://github.com/uber/NullAway/pull/1086. Bail out.
return true;
}
// bail out of checking raw types for now
if (rhsTypeAsSuper.isRaw()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,31 @@ public void issue1019() {
.doTest();
}

@Test
public void issue1082() {
makeHelper()
.addSourceLines(
"Main.java",
"package com.uber;",
"import java.util.Optional;",
"public class Main {",
" public interface Factory<T> {",
" T create();",
" }",
" public interface Expiry<K, V> {}",
" static class Config<K, V> {",
" Config<K, V> setFactory(Optional<Factory<? extends Expiry<K, V>>> factory) {",
" return this;",
" }",
" }",
" static void caller(Config config) {",
" // checking that we don't crash",
" config.setFactory(Optional.<Object>empty());",
" }",
"}")
.doTest();
}

private CompilationTestHelper makeHelper() {
return makeTestHelperWithArgs(
Arrays.asList(
Expand Down

0 comments on commit 933b1af

Please sign in to comment.