diff --git a/nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java b/nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java index 4fe96814d1..8609b53a82 100644 --- a/nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java +++ b/nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java @@ -120,6 +120,18 @@ public Type visitTypeVar(Type.TypeVar t, Type other) { return updated != null ? updated : t; } + @Override + public Type visitForAll(Type.ForAll t, Type other) { + Type methodType = t.qtype; + Type otherMethodType = ((Type.ForAll) other).qtype; + Type newMethodType = visit(methodType, otherMethodType); + if (methodType == newMethodType) { + return t; + } else { + return new Type.ForAll(t.tvars, newMethodType); + } + } + /** * Updates the nullability annotations on a type {@code t} based on the nullability annotations * on a type variable {@code other}. diff --git a/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java b/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java index b391ff60b4..e2c2866e38 100644 --- a/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java @@ -2258,6 +2258,26 @@ public void issue1126() { .doTest(); } + @Test + public void issue1129() { + makeHelper() + .addSourceLines( + "Test.java", + "package com.uber;", + "import org.jspecify.annotations.Nullable;", + "import java.util.function.Consumer;", + "class Test {", + " interface BodySpec> {", + " T value(Consumer<@Nullable B> consumer);", + " }", + " abstract class DefaultBodySpec> implements BodySpec {", + " @Override", + " public abstract T value(Consumer<@Nullable B> consumer);", + " }", + "}") + .doTest(); + } + private CompilationTestHelper makeHelper() { return makeTestHelperWithArgs( Arrays.asList(