Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip checks involving wildcard generic type arguments #1137

Merged
merged 2 commits into from
Jan 31, 2025
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 @@ -55,6 +55,11 @@ public Boolean visitClassType(Type.ClassType lhsType, Type rhsType) {
for (int i = 0; i < lhsTypeArguments.size(); i++) {
Type lhsTypeArgument = lhsTypeArguments.get(i);
Type rhsTypeArgument = rhsTypeArguments.get(i);
if (lhsTypeArgument.getKind().equals(TypeKind.WILDCARD)
|| rhsTypeArgument.getKind().equals(TypeKind.WILDCARD)) {
// TODO Handle wildcard types
continue;
}
boolean isLHSNullableAnnotated = GenericsChecks.isNullableAnnotated(lhsTypeArgument, state);
boolean isRHSNullableAnnotated = GenericsChecks.isNullableAnnotated(rhsTypeArgument, state);
if (isLHSNullableAnnotated != isRHSNullableAnnotated) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,42 @@ public void nullUnmarkedGenericField() {
.doTest();
}

@Test
public void issue1126() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"import java.util.function.Supplier;",
"public class Test {",
" static class K<T extends @Nullable Object> {}",
" void foo(K<@Nullable Object> k) {",
" K<? extends @Nullable Object> k2 = k;",
" Supplier<? extends @Nullable Object> s = () -> null;",
" }",
"}")
.addSourceLines(
"Test2.java",
"package com.uber;",
"import java.util.HashMap;",
"import java.util.Map;",
"import org.jspecify.annotations.Nullable;",
"import org.jetbrains.annotations.Contract;",
"public class Test2 {",
" @Contract(\"null -> true\")",
" public static boolean isEmpty(@Nullable Map<?, ? extends @Nullable Object> map) {",
" return (map == null || map.isEmpty());",
" }",
" static void foo() {",
" Map<String, @Nullable Object> variables = new HashMap<>();",
" if (isEmpty(variables)) { /* do nothing */ }",
" variables.toString();",
" }",
"}")
.doTest();
}

private CompilationTestHelper makeHelper() {
return makeTestHelperWithArgs(
Arrays.asList(
Expand Down