Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/LambdaInlining.java
Tagir Valeev df95dbba8f ControlFlowAnalyzer: store lambda return val to variable when inlining block
Should fix EA-107095 - CCE: ControlTransferInstruction.accept
2017-09-18 14:45:40 +07:00

46 lines
1.1 KiB
Java

import java.util.function.IntSupplier;
public class LambdaInlining {
void testLambdaInline() {
int x = ((IntSupplier) (() -> {
if (Math.random() > 0.5) {
return 4;
}
return 5;
})).getAsInt();
if (<warning descr="Condition 'x == 6' is always 'false'">x == 6</warning>) {
System.out.println("oops");
}
}
void testLambdaTryCatch() {
int x = ((IntSupplier)(() -> {
try {
return Math.random() > 0.5 ? 2 : 3;
}
catch (Exception ex) {
}
return 1;
})).getAsInt();
if(<warning descr="Condition 'x == 0' is always 'false'">x == 0</warning>) {
System.out.println("oops");
}
}
void testLambdaTryFinally() {
int x = ((IntSupplier)() -> {
try {
return 10;
} finally {
return 20;
}
}).getAsInt();
if(<warning descr="Condition 'x == 30' is always 'false'">x == 30</warning>) {
System.out.println("oops");
}
if(<warning descr="Condition 'x < 30' is always 'true'">x < 30</warning>) {
System.out.println("always");
}
}
}