Skip to content

Commit 7ff1e58

Browse files
authored
Merge branch 'master' into issue-1127
2 parents cadf793 + 90265c5 commit 7ff1e58

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

nullaway/src/main/java/com/uber/nullaway/generics/CheckIdenticalNullabilityVisitor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public Boolean visitClassType(Type.ClassType lhsType, Type rhsType) {
5555
for (int i = 0; i < lhsTypeArguments.size(); i++) {
5656
Type lhsTypeArgument = lhsTypeArguments.get(i);
5757
Type rhsTypeArgument = rhsTypeArguments.get(i);
58+
if (lhsTypeArgument.getKind().equals(TypeKind.WILDCARD)
59+
|| rhsTypeArgument.getKind().equals(TypeKind.WILDCARD)) {
60+
// TODO Handle wildcard types
61+
continue;
62+
}
5863
boolean isLHSNullableAnnotated = GenericsChecks.isNullableAnnotated(lhsTypeArgument, state);
5964
boolean isRHSNullableAnnotated = GenericsChecks.isNullableAnnotated(rhsTypeArgument, state);
6065
if (isLHSNullableAnnotated != isRHSNullableAnnotated) {

nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,6 +2084,42 @@ public void nullUnmarkedGenericField() {
20842084
.doTest();
20852085
}
20862086

2087+
@Test
2088+
public void issue1126() {
2089+
makeHelper()
2090+
.addSourceLines(
2091+
"Test.java",
2092+
"package com.uber;",
2093+
"import org.jspecify.annotations.Nullable;",
2094+
"import java.util.function.Supplier;",
2095+
"public class Test {",
2096+
" static class K<T extends @Nullable Object> {}",
2097+
" void foo(K<@Nullable Object> k) {",
2098+
" K<? extends @Nullable Object> k2 = k;",
2099+
" Supplier<? extends @Nullable Object> s = () -> null;",
2100+
" }",
2101+
"}")
2102+
.addSourceLines(
2103+
"Test2.java",
2104+
"package com.uber;",
2105+
"import java.util.HashMap;",
2106+
"import java.util.Map;",
2107+
"import org.jspecify.annotations.Nullable;",
2108+
"import org.jetbrains.annotations.Contract;",
2109+
"public class Test2 {",
2110+
" @Contract(\"null -> true\")",
2111+
" public static boolean isEmpty(@Nullable Map<?, ? extends @Nullable Object> map) {",
2112+
" return (map == null || map.isEmpty());",
2113+
" }",
2114+
" static void foo() {",
2115+
" Map<String, @Nullable Object> variables = new HashMap<>();",
2116+
" if (isEmpty(variables)) { /* do nothing */ }",
2117+
" variables.toString();",
2118+
" }",
2119+
"}")
2120+
.doTest();
2121+
}
2122+
20872123
private CompilationTestHelper makeHelper() {
20882124
return makeTestHelperWithArgs(
20892125
Arrays.asList(

0 commit comments

Comments
 (0)