diff --git a/nullaway/src/main/java/com/uber/nullaway/ErrorMessage.java b/nullaway/src/main/java/com/uber/nullaway/ErrorMessage.java index 22ebf13b4b..f451a921a8 100644 --- a/nullaway/src/main/java/com/uber/nullaway/ErrorMessage.java +++ b/nullaway/src/main/java/com/uber/nullaway/ErrorMessage.java @@ -55,7 +55,6 @@ public enum MessageTypes { TYPE_PARAMETER_CANNOT_BE_NULLABLE, ASSIGN_GENERIC_NULLABLE, RETURN_NULLABLE_GENERIC, - PASS_NULLABLE_GENERIC, } public String getMessage() { diff --git a/nullaway/src/main/java/com/uber/nullaway/GenericsChecks.java b/nullaway/src/main/java/com/uber/nullaway/GenericsChecks.java index 13ffd147f2..8905098c83 100644 --- a/nullaway/src/main/java/com/uber/nullaway/GenericsChecks.java +++ b/nullaway/src/main/java/com/uber/nullaway/GenericsChecks.java @@ -168,26 +168,6 @@ private static void reportMismatchedTypeForTernaryOperator( errorMessage, analysis.buildDescription(tree), state, null)); } - private void reportInvalidParametersNullabilityError( - Type formalParameterType, - Type actualParameterType, - ExpressionTree paramExpression, - VisitorState state, - NullAway analysis) { - ErrorBuilder errorBuilder = analysis.getErrorBuilder(); - ErrorMessage errorMessage = - new ErrorMessage( - ErrorMessage.MessageTypes.PASS_NULLABLE_GENERIC, - "Cannot pass parameter of type " - + actualParameterType - + ", as formal parameter has type " - + formalParameterType - + ", which has mismatched type parameter nullability"); - state.reportMatch( - errorBuilder.createErrorDescription( - errorMessage, analysis.buildDescription(paramExpression), state, null)); - } - /** * This method returns the type of the given tree, including any type use annotations. * @@ -449,59 +429,4 @@ public void checkTypeParameterNullnessForConditionalExpression(ConditionalExpres } } } - - /** - * Checks that for each parameter p at a call, the type parameter nullability for p's type matches - * that of the corresponding formal parameter. If a mismatch is found, report an error. - * - * @param formalParams the formal parameters - * @param actualParams the actual parameters - * @param isVarArgs true if the call is to a varargs method - */ - public void compareGenericTypeParameterNullabilityForCall( - List formalParams, - List actualParams, - boolean isVarArgs) { - if (!config.isJSpecifyMode()) { - return; - } - int n = formalParams.size(); - if (isVarArgs) { - // If the last argument is var args, don't check it now, it will be checked against - // all remaining actual arguments in the next loop. - n = n - 1; - } - for (int i = 0; i < n - 1; i++) { - Type formalParameter = formalParams.get(i).type; - if (!formalParameter.getTypeArguments().isEmpty()) { - Type actualParameter = getTreeType(actualParams.get(i)); - if (formalParameter instanceof Type.ClassType - && actualParameter instanceof Type.ClassType) { - if (!compareNullabilityAnnotations( - (Type.ClassType) formalParameter, (Type.ClassType) actualParameter)) { - reportInvalidParametersNullabilityError( - formalParameter, actualParameter, actualParams.get(i), state, analysis); - } - } - } - } - if (isVarArgs && !formalParams.isEmpty()) { - Type.ArrayType varargsArrayType = - (Type.ArrayType) formalParams.get(formalParams.size() - 1).type; - Type varargsElementType = varargsArrayType.elemtype; - if (varargsElementType.getTypeArguments().size() > 0) { - for (int i = formalParams.size() - 1; i < actualParams.size(); i++) { - Type actualParameter = getTreeType(actualParams.get(i)); - if (varargsElementType instanceof Type.ClassType - && actualParameter instanceof Type.ClassType) { - if (!compareNullabilityAnnotations( - (Type.ClassType) varargsElementType, (Type.ClassType) actualParameter)) { - reportInvalidParametersNullabilityError( - varargsElementType, actualParameter, actualParams.get(i), state, analysis); - } - } - } - } - } - } } diff --git a/nullaway/src/main/java/com/uber/nullaway/NullAway.java b/nullaway/src/main/java/com/uber/nullaway/NullAway.java index 62d49d2a23..ee15f9b6f4 100644 --- a/nullaway/src/main/java/com/uber/nullaway/NullAway.java +++ b/nullaway/src/main/java/com/uber/nullaway/NullAway.java @@ -1624,9 +1624,6 @@ private Description handleInvocation( : Nullness.NONNULL; } } - new GenericsChecks(state, config, this) - .compareGenericTypeParameterNullabilityForCall( - formalParams, actualParams, methodSymbol.isVarArgs()); } // Allow handlers to override the list of non-null argument positions diff --git a/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java b/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java index b16dd52cc7..e2291d42d3 100644 --- a/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/NullAwayJSpecifyGenericsTests.java @@ -662,62 +662,6 @@ public void ternaryMismatchedAssignmentContext() { .doTest(); } - @Test - public void parameterPassing() { - makeHelper() - .addSourceLines( - "Test.java", - "package com.uber;", - "import org.jspecify.annotations.Nullable;", - "class Test {", - "static class A { }", - " static A sampleMethod1(A> a1, A a2) {", - " return a2;", - " }", - " static A sampleMethod2(A> a1, A a2) {", - " return a2;", - " }", - " static void testPositive1(A> a1, A a2) {", - " // BUG: Diagnostic contains: Cannot pass parameter of type", - " A a = sampleMethod1(a1, a2);", - " }", - " static void testPositive2(A> a1, A a2) {", - " // BUG: Diagnostic contains: Cannot pass parameter of type", - " A a = sampleMethod2(a1, a2);", - " }", - " static void testNegative(A> a1, A a2) {", - " A a = sampleMethod1(a1, a2);", - " }", - "}") - .doTest(); - } - - @Test - public void varargsParameter() { - makeHelper() - .addSourceLines( - "Test.java", - "package com.uber;", - "import org.jspecify.annotations.Nullable;", - "class Test {", - " static class A { }", - " static A<@Nullable String> sampleMethodWithVarArgs(A... args) {", - " return new A<@Nullable String>();", - " }", - " static void testPositive(A<@Nullable String> a1, A a2) {", - " // BUG: Diagnostic contains: Cannot pass parameter of type", - " A<@Nullable String> b = sampleMethodWithVarArgs(a1);", - " // BUG: Diagnostic contains: Cannot pass parameter of type", - " A<@Nullable String> b2 = sampleMethodWithVarArgs(a2, a1);", - " }", - " static void testNegative(A a1, A a2) {", - " A<@Nullable String> b = sampleMethodWithVarArgs(a1);", - " A<@Nullable String> b2 = sampleMethodWithVarArgs(a2, a1);", - " }", - "}") - .doTest(); - } - private CompilationTestHelper makeHelper() { return makeTestHelperWithArgs( Arrays.asList(