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 @@ -7,6 +7,7 @@
import com.sun.tools.javac.code.BoundKind;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Type.CapturedType;
import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.code.Type.TypeVar;
import com.sun.tools.javac.code.Type.WildcardType;
Expand Down Expand Up @@ -155,6 +156,11 @@ class AddSubtypeConstraintsVisitor extends Types.DefaultTypeVisitor<@Nullable Vo
return visitType(subtype, supertype);
}

@Override
public @Nullable Void visitCapturedType(CapturedType subtype, Type supertype) {
return visitTypeVar(subtype, supertype);
}

@Override
public @Nullable Void visitWildcardType(WildcardType subtype, Type supertype) {
if (config.handleWildcardGenerics()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ public Type visitTypeVar(Type.TypeVar t, Type other) {
return updateDirectNullabilityAnnotationsForType(t, other);
}

@Override
public Type visitCapturedType(Type.CapturedType t, Type other) {
return updateDirectNullabilityAnnotationsForType(t, other);
}

@Override
public Type visitForAll(Type.ForAll t, Type other) {
Type methodType = t.qtype;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,65 @@ class Bar {
.doTest();
}

@Test
public void varAndGenericInference() {
makeHelper()
.addSourceLines(
"Test.java",
"""
import java.util.concurrent.CompletableFuture;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
@NullMarked
Comment thread
coderabbitai[bot] marked this conversation as resolved.
final class Test {
static void reproduce() {
var future = future();
run(() -> future.join());
}
private static CompletableFuture<?> future() {
return new CompletableFuture<>();
}
private static <T extends @Nullable Object> T run(Action<T> action) {
return action.run();
}
private interface Action<T extends @Nullable Object> {
T run();
}
}
""")
.doTest();
}
Comment on lines +183 to +210

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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Add Javadoc for the new non-trivial test methods.

  • nullaway/src/test/java/com/uber/nullaway/jspecify/GenericLambdaTests.java#L183-L210: Document the nullable-upper-bound inference scenario.
  • nullaway/src/test/java/com/uber/nullaway/jspecify/GenericLambdaTests.java#L212-L240: Document the conflicting non-null upper-bound diagnostic scenario.

As per coding guidelines, “Add Javadoc to every non-trivial method, including private methods.”

📍 Affects 1 file
  • nullaway/src/test/java/com/uber/nullaway/jspecify/GenericLambdaTests.java#L183-L210 (this comment)
  • nullaway/src/test/java/com/uber/nullaway/jspecify/GenericLambdaTests.java#L212-L240
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@nullaway/src/test/java/com/uber/nullaway/jspecify/GenericLambdaTests.java`
around lines 183 - 210, Add Javadoc describing the nullable-upper-bound
inference scenario for varAndGenericInference in
nullaway/src/test/java/com/uber/nullaway/jspecify/GenericLambdaTests.java lines
183-210. Also add Javadoc describing the conflicting non-null upper-bound
diagnostic scenario for the test method in lines 212-240; no other changes are
needed.

Source: Coding guidelines


@Test
public void varAndGenericInferenceWithNonNullUpperBound() {
makeHelper()
.addSourceLines(
"Test.java",
"""
import java.util.concurrent.CompletableFuture;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.NonNull;
@NullMarked
final class Test {
static void reproduce() {
var future = future();
// BUG: Diagnostic contains: inference failure: type variable T constrained to be both @NonNull and @Nullable
run(() -> future.join());
}
private static CompletableFuture<?> future() {
return new CompletableFuture<>();
}
private static <T> T run(Action<T> action) {
return action.run();
}
private interface Action<T> {
T run();
}
}
""")
.doTest();
}

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