Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix another JSpecify mode crash involving raw types #1086

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading