mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-68815 ConstantConditions inspection inside timers
This commit is contained in:
@@ -1434,7 +1434,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
if (dfaValue instanceof DfaVariableValue) {
|
||||
DfaVariableValue dfaVariable = (DfaVariableValue)dfaValue;
|
||||
PsiVariable psiVariable = dfaVariable.getPsiVariable();
|
||||
if (psiVariable instanceof PsiField && !psiVariable.hasModifierProperty(PsiModifier.FINAL)) {
|
||||
if (psiVariable instanceof PsiField) {
|
||||
addField(dfaVariable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,6 +286,7 @@ public class DataFlowInspection extends BaseLocalInspectionTool {
|
||||
PsiField field = (PsiField)resolved;
|
||||
|
||||
if (!field.hasModifierProperty(PsiModifier.FINAL)) return false;
|
||||
if (!field.hasModifierProperty(PsiModifier.STATIC)) return false;
|
||||
|
||||
PsiElement parent = element.getParent();
|
||||
if (parent instanceof PsiPrefixExpression && ((PsiPrefixExpression)parent).getOperationTokenType() == JavaTokenType.EXCL) {
|
||||
|
||||
@@ -229,7 +229,9 @@ public class DataFlowRunner {
|
||||
@Override
|
||||
public DfaInstructionState[] visitMethodCall(MethodCallInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
|
||||
if (myNewExpression == instruction.getCallExpression()) {
|
||||
myClosureStates.add(memState.createCopy());
|
||||
DfaMemoryState copy = memState.createCopy();
|
||||
copy.flushFields(runner);
|
||||
myClosureStates.add(copy);
|
||||
}
|
||||
return super.visitMethodCall(instruction, runner, memState);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.intellij.codeInspection.dataFlow.value.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.psi.JavaTokenType;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
@@ -678,6 +679,10 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
}
|
||||
|
||||
public void flushVariable(@NotNull DfaVariableValue variable) {
|
||||
if (variable.getPsiVariable().hasModifierProperty(PsiModifier.FINAL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int id = variable.getID();
|
||||
int size = myEqClasses.size();
|
||||
int interruptCount = 0;
|
||||
|
||||
@@ -78,7 +78,7 @@ public class DfaValueFactory {
|
||||
PsiExpression initializer = variable.getInitializer();
|
||||
if (initializer instanceof PsiPolyadicExpression && variable.hasModifierProperty(PsiModifier.FINAL)) {
|
||||
PsiType type = initializer.getType();
|
||||
if (type != null && type.equalsToText("java.lang.String")) {
|
||||
if (type != null && type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
|
||||
return getNotNullFactory().create(type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
class Zoo2 {
|
||||
private boolean condition;
|
||||
private final boolean condition2;
|
||||
|
||||
Zoo2(boolean condition2) {
|
||||
this.condition2 = condition2;
|
||||
}
|
||||
|
||||
Runnable foo() {
|
||||
if (!condition) {
|
||||
return new Runnable() {
|
||||
|
||||
public void run() {
|
||||
if (condition) {
|
||||
System.out.println("aaa");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
if (!condition2) {
|
||||
return new Runnable() {
|
||||
|
||||
public void run() {
|
||||
if (<warning descr="Condition 'condition2' is always 'false'">condition2</warning>) {
|
||||
System.out.println("aaa");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
return <warning descr="'null' is returned by the method which isn't declared as @Nullable">null</warning>;
|
||||
}
|
||||
|
||||
public void setCondition(boolean condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
}
|
||||
@@ -32,4 +32,6 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas
|
||||
public void testNullableAnonymousVolatile() throws Throwable { doTest(); }
|
||||
public void testNullableAnonymousVolatileNotNull() throws Throwable { doTest(); }
|
||||
|
||||
public void testFieldInAnonymous() throws Throwable { doTest(); }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user