[java] allows nulls to nullable parameters (IDEA-193726)

This commit is contained in:
Roman Shevchenko
2018-06-11 18:56:53 +03:00
parent 1747ed7fda
commit 15fa931c9f
3 changed files with 20 additions and 18 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection.nullable;
import com.intellij.codeInsight.*;
@@ -822,12 +822,14 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
int parameterIdx,
PsiParameter parameter) {
if (!REPORT_NULLS_PASSED_TO_NOT_NULL_PARAMETER || !isOnFly) return;
PsiElement elementToHighlight;
if (DfaPsiUtil.getTypeNullability(getMemberType(parameter)) == Nullability.NOT_NULL) {
elementToHighlight = parameter.getNameIdentifier();
} else {
}
else {
NullabilityAnnotationInfo info = nullableManager.findOwnNullabilityAnnotationInfo(parameter);
if (info == null || info.isInferred()) return;
if (info == null || info.getNullability() != Nullability.NOT_NULL || info.isInferred()) return;
PsiAnnotation notNullAnnotation = info.getAnnotation();
boolean physical = PsiTreeUtil.isAncestor(parameter, notNullAnnotation, true);
elementToHighlight = physical ? notNullAnnotation : parameter.getNameIdentifier();
@@ -0,0 +1,11 @@
import org.jetbrains.annotations.Nullable;
class AcceptsNull {
void recepient(@Nullable String s) {
System.out.println("s=" + s);
}
void donor() {
recepient(null);
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.codeInspection;
@@ -302,4 +288,7 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase
myFixture.checkResultByFile(getTestName(false) + "_after.java");
}
public void testNullPassedToNullableParameter() {
doTest();
}
}