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 @@ -359,6 +359,9 @@ static void callSite(
Map<String, String> map,
BiFunction<String, @Nullable String, @Nullable String> remappingFunction) {
map.compute("key", remappingFunction);
String value = map.compute("key", remappingFunction);
// BUG: Diagnostic contains: dereferenced expression 'value' is @Nullable
value.length();
}
@Override
public @Nullable String compute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,84 @@ static void anonymousClasses() {
.doTest();
}

/**
* Fails when a diamond anonymous class loses the {@code @Nullable} on its supertype's type
* argument. See https://github.com/uber/NullAway/issues/1746
*/
@Test
public void overrideDiamondAnonymousClassWithNestedGenericTypes() {
makeHelper()
.addSourceLines(
"Test.java",
"""
package com.uber;
import java.util.List;
import org.jspecify.annotations.Nullable;
class Test {
interface Foo<T extends @Nullable Object> {
List<T> get();
void accept(List<T> values);
}
static void test() {
Foo<@Nullable String> foo = new Foo<>() {
@Override
public List<@Nullable String> get() { throw new AssertionError(); }
@Override
public void accept(List<@Nullable String> values) {}
};
Foo<@Nullable String> badFoo = new Foo<>() {
@Override
// BUG: Diagnostic contains: mismatched type parameter nullability
public List<String> get() { throw new AssertionError(); }
@Override
// BUG: Diagnostic contains: mismatched type parameter nullability
public void accept(List<String> values) {}
};
}
}
""")
.doTest();
}

/**
* Fails when an anonymous class loses the {@code @Nullable} on its supertype's type argument and
* the override wraps the type variable in an array. See
* https://github.com/uber/NullAway/issues/1746
*/
@Test
public void overrideAnonymousClassWithArrayOfTypeVariable() {
makeHelper()
.addSourceLines(
"Test.java",
"""
package com.uber;
import org.jspecify.annotations.Nullable;
class Test {
interface Foo<T extends @Nullable Object> {
T[] get();
void accept(T[] values);
}
static void test() {
Foo<@Nullable String> explicit = new Foo<@Nullable String>() {
@Override
public @Nullable String[] get() { throw new AssertionError(); }
@Override
// BUG: Diagnostic contains: Parameter has type String [], but overridden method has parameter type @Nullable String []
public void accept(String[] values) {}
};
Foo<@Nullable String> diamond = new Foo<>() {
@Override
public @Nullable String[] get() { throw new AssertionError(); }
@Override
// BUG: Diagnostic contains: Parameter has type String [], but overridden method has parameter type @Nullable String []
public void accept(String[] values) {}
};
}
}
""")
.doTest();
}

@Test
public void nullableGenericTypeVariableReturnType() {
makeHelper()
Expand Down