Skip to content
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 @@ -459,7 +459,14 @@ private void reportInvalidOverridingMethodParamTypeError(
}
}
}
result = symbol.type;
result = ASTHelpers.getType(tree);
// type on the tree itself can be missing nested annotations in certain cases, so use the
// type on the symbol instead. for type variables, we've found that the type on the symbol
// can be wrong (which caused https://github.com/uber/NullAway/issues/1377), so we still use
// the tree type for type variables
if (result != null && !(result instanceof Type.TypeVar)) {
result = symbol.type;
}
} else if (tree instanceof AssignmentTree) {
// type on the tree itself can be missing nested annotations for arrays; get the type from
// the symbol for the assigned location instead, if available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2753,6 +2753,58 @@ public void nonNullInFieldTypeArg() {
.doTest();
}

@Test
public void issue1377() {
makeHelper()
.addSourceLines(
"Test.java",
"import org.jspecify.annotations.NullMarked;",
"@NullMarked",
"class Test {",
"interface Marker {}",
"class Generic<T> {",
" public void method() {}",
"}",
"class Base<T extends Object & Marker> {",
" T instance;",
" Base(T instance) {",
" this.instance = instance;",
" }",
"}",
"class SubClass<T extends Generic<Integer> & Marker> extends Base<T> {",
" SubClass(T instance) {",
" super(instance);",
" }",
" void method() {",
" instance.method();",
" }",
"}",
"}")
.doTest();
}
Comment on lines +2756 to +2784

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Regression test looks good, consider adding explanatory comment.

The test appropriately covers the intersection bound scenario from issue #1377, ensuring NullAway doesn't throw an NPE when analyzing method invocations on inherited generic fields with intersection-bounded type parameters (e.g., T extends Generic<Integer> & Marker).

Consider adding a brief comment at the beginning of the test method to document that this is a regression test for issue #1377:

 @Test
 public void issue1377() {
+  // Regression test for https://github.com/uber/NullAway/issues/1377
+  // Ensures no NPE when analyzing intersection-bounded type variables in JSpecify mode
   makeHelper()

This would help future maintainers understand the test's purpose.

🤖 Prompt for AI Agents
In nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java around
lines 2756 to 2784, add a brief Java comment at the start of the issue1377()
test method (immediately before the makeHelper() call) noting that this is a
regression test for issue #1377 and explaining concisely that it verifies
NullAway does not NPE when analyzing method invocations on inherited generic
fields with intersection-bounded type parameters (e.g., T extends
Generic<Integer> & Marker). This comment should be one or two lines, mention the
specific scenario being tested and the bug being prevented, and then keep the
rest of the test unchanged.


@Test
public void annotationsOnTypeVariableTypeArgs() {
makeHelper()
.addSourceLines(
"Test.java",
"import org.jspecify.annotations.*;",
"import java.util.function.Function;",
"@NullMarked",
"class Test {",
" static final class Foo<T> {",
" final Function<@Nullable T, @Nullable T> func;",
" Foo(Function<@Nullable T, @Nullable T> func) {",
" this.func = func;",
" }",
" @Nullable T test(@Nullable T t) {",
" return func.apply(t);",
" }",
" }",
"}")
.doTest();
}

private CompilationTestHelper makeHelper() {
return makeTestHelperWithArgs(
JSpecifyJavacConfig.withJSpecifyModeArgs(
Expand Down