mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: don't report null comparisons as uninitialized read (IDEA-61057)
This commit is contained in:
+3
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2008 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -90,12 +90,8 @@ public class StaticVariableUninitializedUseInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
}
|
||||
final PsiClassInitializer[] initializers =
|
||||
containingClass.getInitializers();
|
||||
// Do the static initializers come in actual order in file?
|
||||
// (They need to.)
|
||||
final UninitializedReadCollector uninitializedReadCollector =
|
||||
new UninitializedReadCollector();
|
||||
final PsiClassInitializer[] initializers = containingClass.getInitializers();
|
||||
final UninitializedReadCollector uninitializedReadCollector = new UninitializedReadCollector();
|
||||
boolean assigned = false;
|
||||
for (final PsiClassInitializer initializer : initializers) {
|
||||
if (!initializer.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -406,7 +406,7 @@ public class UninitializedReadCollector {
|
||||
|
||||
private boolean assignmentExpressionAssignsVariable(@NotNull PsiAssignmentExpression assignment, @NotNull PsiVariable variable,
|
||||
int stamp, @NotNull Set<MethodSignature> checkedMethods) {
|
||||
final PsiExpression lhs = assignment.getLExpression();
|
||||
final PsiExpression lhs = ParenthesesUtils.stripParentheses(assignment.getLExpression());
|
||||
if (expressionAssignsVariable(lhs, variable, stamp, checkedMethods)) {
|
||||
return true;
|
||||
}
|
||||
@@ -430,7 +430,7 @@ public class UninitializedReadCollector {
|
||||
return true;
|
||||
}
|
||||
if (variable.equals(referenceExpression.resolve())) {
|
||||
final PsiElement parent = referenceExpression.getParent();
|
||||
final PsiElement parent = ParenthesesUtils.getParentSkipParentheses(referenceExpression);
|
||||
if (parent instanceof PsiAssignmentExpression) {
|
||||
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)parent;
|
||||
final PsiExpression rhs = assignmentExpression.getRExpression();
|
||||
@@ -438,7 +438,7 @@ public class UninitializedReadCollector {
|
||||
checkReferenceExpression(referenceExpression, variable, qualifierExpression);
|
||||
}
|
||||
}
|
||||
else {
|
||||
else if (!(parent instanceof PsiExpression) || !ComparisonUtils.isNullComparison((PsiExpression)parent)) {
|
||||
checkReferenceExpression(referenceExpression, variable, qualifierExpression);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports reads of instance variables which are not yet initialized.
|
||||
Reports instance variables which are read prior to initialization.
|
||||
Equality checks with <b>null</b> are ignored by this inspection.
|
||||
<p>
|
||||
Note: This inspection uses a very conservative dataflow algorithm, and may report instance variables
|
||||
as uninitialized incorrectly. Variables reported as initialized will always be initialized.
|
||||
|
||||
+1
@@ -1,6 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports <b>static</b> variables which are read prior to initialization.
|
||||
Equality checks with <b>null</b> are ignored by this inspection.
|
||||
<p>
|
||||
Note: This inspection uses a very conservative dataflow algorithm, and may report static variables
|
||||
used uninitialized incorrectly. Variables reported as initialized will always be initialized.
|
||||
|
||||
+7
@@ -34,4 +34,11 @@ public class StaticVariableUninitializedUse {
|
||||
static int foo() {
|
||||
return <warning descr="Static field 'i' used before initialization">i</warning>;
|
||||
}
|
||||
|
||||
private static String T;
|
||||
static {
|
||||
System.out.println((T) != (null));
|
||||
(T) = "null";
|
||||
System.out.println((T));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user