Skip to content

Commit

Permalink
fix ClassCastException
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Jan 31, 2025
1 parent 427fa89 commit ec0f65e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,17 @@ private static boolean[] getTypeParamsWithNullableUpperBound(
*/
public static void checkGenericMethodCallTypeArguments(
Tree tree, VisitorState state, NullAway analysis, Config config, Handler handler) {
List<? extends Tree> typeArguments = ((MethodInvocationTree) tree).getTypeArguments();
List<? extends Tree> typeArguments;
switch (tree.getKind()) {
case METHOD_INVOCATION:
typeArguments = ((MethodInvocationTree) tree).getTypeArguments();
break;
case NEW_CLASS:
typeArguments = ((NewClassTree) tree).getTypeArguments();
break;
default:
throw new RuntimeException("Unexpected tree kind: " + tree.getKind());

Check warning on line 172 in nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java

View check run for this annotation

Codecov / codecov/patch

nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java#L172

Added line #L172 was not covered by tests
}
if (typeArguments.isEmpty()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,24 @@ public void issue1035() {
.doTest();
}

@Test
public void issue1138() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.NullMarked;",
"@NullMarked",
"class Foo {",
" <T> Foo(T source) {",
" }",
" static <T> Foo create(T in) {",
" return new Foo(in);",
" }",
"}")
.doTest();
}

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

0 comments on commit ec0f65e

Please sign in to comment.