mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-21 14:01:44 +07:00
Java control flow: Added conditional branch that bypasses assert statement because assertions can be disabled (IDEA-71526)
This commit is contained in:
@@ -986,6 +986,12 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
public void visitAssertStatement(PsiAssertStatement statement) {
|
||||
startElement(statement);
|
||||
|
||||
myStartStatementStack.pushStatement(statement, false);
|
||||
myEndStatementStack.pushStatement(statement, false);
|
||||
Instruction passByWhenAssertionsDisabled = new ConditionalGoToInstruction(0, BranchingInstruction.Role.END, null);
|
||||
myCurrentFlow.addInstruction(passByWhenAssertionsDisabled);
|
||||
addElementOffsetLater(statement, false);
|
||||
|
||||
// should not try to compute constant expression within assert
|
||||
// since assertions can be disabled/enabled at any moment via JVM flags
|
||||
|
||||
@@ -1014,6 +1020,9 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
myCurrentFlow.addInstruction(instruction);
|
||||
addElementOffsetLater(myCodeFragment, false);
|
||||
|
||||
myStartStatementStack.popStatement();
|
||||
myEndStatementStack.popStatement();
|
||||
|
||||
finishElement(statement);
|
||||
}
|
||||
|
||||
|
||||
@@ -274,4 +274,12 @@ class InitializedInClassInitializerUsedInTheFollowingFieldInitializer {
|
||||
{
|
||||
k = 1;
|
||||
}
|
||||
}
|
||||
|
||||
class AssignInAssert {
|
||||
<error descr="Variable 'b' might not have been initialized">private final boolean b</error>;
|
||||
|
||||
AssignInAssert() {
|
||||
assert b = true;
|
||||
}
|
||||
}
|
||||
@@ -435,4 +435,13 @@ class ClassInitializerConstantEval {
|
||||
<error descr="Variable 'x' might already have been assigned to">x</error> = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AssignInAssert {
|
||||
void f() {
|
||||
boolean a;
|
||||
assert a = true;
|
||||
if(<error descr="Variable 'a' might not have been initialized">a</error>)
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
7
java/java-tests/testData/psi/controlFlow/flowAssert.java
Normal file
7
java/java-tests/testData/psi/controlFlow/flowAssert.java
Normal file
@@ -0,0 +1,7 @@
|
||||
// LocalsOrMyInstanceFieldsControlFlowPolicy
|
||||
class A {
|
||||
void f(boolean b) {<caret>
|
||||
assert b;
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
4
java/java-tests/testData/psi/controlFlow/flowAssert.txt
Normal file
4
java/java-tests/testData/psi/controlFlow/flowAssert.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
0: COND_GOTO [END] 3
|
||||
1: READ b
|
||||
2: COND_THROW_TO 4
|
||||
3: EMPTY
|
||||
Reference in New Issue
Block a user