IDEA-178172 Good code is yellow: Inspection "@NotNull/@Nullable problems": @NotNull field with non-trivial setter

This commit is contained in:
peter
2017-08-31 17:39:08 +02:00
parent ee3d96da1a
commit 59b8dd7dc6
3 changed files with 19 additions and 1 deletions
@@ -407,7 +407,7 @@ public class NullableStuffInspectionBase extends BaseJavaBatchLocalInspectionToo
final PsiClass containingClass = field.getContainingClass();
final PsiMethod setter = PropertyUtil.findPropertySetter(containingClass, propName, isStatic, false);
if (setter != null && setter.isPhysical()) {
if (setter != null && setter.isPhysical() && PropertyUtil.isSimpleSetter(setter)) {
final PsiParameter[] parameters = setter.getParameterList().getParameters();
assert parameters.length == 1 : setter.getText();
final PsiParameter parameter = parameters[0];
@@ -0,0 +1,16 @@
import org.jetbrains.annotations.NotNull;
class Foo {
private static final Long DEFAULT_ID = -1L;
@NotNull
private Long id = DEFAULT_ID;
public Long getId() {
return id > 0 ? id : 42;
}
public void setId(Long id) {
this.id = id != null ? id : DEFAULT_ID;
}
}
@@ -98,6 +98,8 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase
public void testNotNullAnnotationChecksInChildClassMethods() { doTest(); }
public void testGetterSetterProblems() { doTest(); }
public void testNonTrivialGettersSetters() { doTest(); }
public void testOverriddenMethods() {
myInspection.REPORT_ANNOTATION_NOT_PROPAGATED_TO_OVERRIDERS = true;
doTest();