From 6e396e7d44572288ba50abd4d075c69a4c289001 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Fri, 28 Jun 2024 15:19:25 +0200 Subject: [PATCH 1/5] failing test --- .../uber/nullaway/jspecify/GenericsTests.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 e1294b460f..b1a523379a 100644 --- a/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java @@ -1737,6 +1737,26 @@ public void testRawTypeReceiverCast() { .doTest(); } + @Test + public void testRawFormalParameterType() { + makeHelper() + .addSourceLines( + "Test.java", + "package com.uber;", + "class Test {", + " static class A {", + " void foo(T n) {}", + " }", + " static class B {", + " static void bar(A a) {}", + " static void baz(A a) {", + " bar(a);", + " }", + " }", + "}") + .doTest(); + } + @Test public void testUseOfUnannotatedCode() { makeHelper() From b991972b9ad252efded62414b87bfd5a41cf344c Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Fri, 28 Jun 2024 15:21:08 +0200 Subject: [PATCH 2/5] initial fix, more needed --- .../main/java/com/uber/nullaway/generics/GenericsChecks.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java b/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java index 52d54fabc9..e5006509d0 100644 --- a/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java +++ b/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java @@ -511,6 +511,11 @@ public static void compareGenericTypeParameterNullabilityForCall( } for (int i = 0; i < n; i++) { Type formalParameter = formalParams.get(i).type; + // TODO also check on return types, assignments to locals, assignments to fields, etc. + if (formalParameter.isRaw()) { + // bail out of any checking involving raw types for now + return; + } Type actualParameter = getTreeType(actualParams.get(i), state); if (actualParameter != null) { if (!subtypeParameterNullability(formalParameter, actualParameter, state)) { From c8bb0e35493a876996d948c905590ce7abb922e9 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Sat, 29 Jun 2024 09:23:13 +0200 Subject: [PATCH 3/5] more --- .../com/uber/nullaway/generics/GenericsChecks.java | 4 ++++ .../com/uber/nullaway/jspecify/GenericsTests.java | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java b/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java index e5006509d0..0b19257f9f 100644 --- a/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java +++ b/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java @@ -356,6 +356,10 @@ public static void checkTypeParameterNullnessForFunctionReturnType( } Type formalReturnType = methodSymbol.getReturnType(); + if (formalReturnType.isRaw()) { + // bail out of any checking involving raw types for now + return; + } Type returnExpressionType = getTreeType(retExpr, state); if (formalReturnType != null && returnExpressionType != null) { boolean isReturnTypeValid = 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 b1a523379a..2095372779 100644 --- a/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java @@ -1738,20 +1738,28 @@ public void testRawTypeReceiverCast() { } @Test - public void testRawFormalParameterType() { + public void pseudoAssignmentWithRawDeclaredTypes() { makeHelper() .addSourceLines( "Test.java", "package com.uber;", + "import org.jspecify.annotations.Nullable;", "class Test {", " static class A {", " void foo(T n) {}", " }", " static class B {", " static void bar(A a) {}", - " static void baz(A a) {", + " static void m1(A a) {", " bar(a);", " }", + " static A m2(A a) {", + " return a;", + " }", + " @Nullable A field;", + " void m3(A a) {", + " field = a;", + " }", " }", "}") .doTest(); From 4d165b0a690bd3d05468ee6e1d1d4e0d18b1b209 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Sat, 29 Jun 2024 09:32:32 +0200 Subject: [PATCH 4/5] more tests --- .../src/test/java/com/uber/nullaway/jspecify/GenericsTests.java | 2 ++ 1 file changed, 2 insertions(+) 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 3a630689ae..50cf520d85 100644 --- a/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericsTests.java @@ -1760,6 +1760,8 @@ public void pseudoAssignmentWithRawDeclaredTypes() { " @Nullable A field;", " void m3(A a) {", " field = a;", + " A local = a;", + " local = a;", " }", " }", "}") From b0653e4d0f491ef6433a3517083e8a6d4c80f701 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Sat, 29 Jun 2024 09:34:17 +0200 Subject: [PATCH 5/5] remove todo --- .../src/main/java/com/uber/nullaway/generics/GenericsChecks.java | 1 - 1 file changed, 1 deletion(-) diff --git a/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java b/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java index 0b19257f9f..cac2ac7bfc 100644 --- a/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java +++ b/nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java @@ -515,7 +515,6 @@ public static void compareGenericTypeParameterNullabilityForCall( } for (int i = 0; i < n; i++) { Type formalParameter = formalParams.get(i).type; - // TODO also check on return types, assignments to locals, assignments to fields, etc. if (formalParameter.isRaw()) { // bail out of any checking involving raw types for now return;