StreamApiMigrationInspection: NPE fixed (EA-91387)

This commit is contained in:
Tagir Valeev
2016-11-09 12:27:15 +07:00
parent 49b560fbf4
commit ff8a32476a
2 changed files with 20 additions and 3 deletions
@@ -1292,6 +1292,7 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
// At least one previous operation is present (stream source)
private TerminalBlock(@NotNull Operation previousOp, @NotNull PsiVariable variable, @NotNull PsiStatement... statements) {
for(PsiStatement statement : statements) Objects.requireNonNull(statement);
myVariable = variable;
while(true) {
if(statements.length == 1 && statements[0] instanceof PsiBlockStatement) {
@@ -1345,8 +1346,10 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
if(getSingleStatement() instanceof PsiIfStatement) {
PsiIfStatement ifStatement = (PsiIfStatement)getSingleStatement();
if(ifStatement.getElseBranch() == null && ifStatement.getCondition() != null) {
return new TerminalBlock(new FilterOp(myPreviousOp, ifStatement.getCondition(), myVariable, false),
myVariable, ifStatement.getThenBranch());
PsiStatement thenBranch = ifStatement.getThenBranch();
if(thenBranch != null) {
return new TerminalBlock(new FilterOp(myPreviousOp, ifStatement.getCondition(), myVariable, false), myVariable, thenBranch);
}
}
}
if(myStatements.length >= 1) {
@@ -1518,7 +1521,7 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
}
@NotNull
public static TerminalBlock from(StreamSource source, PsiStatement body) {
public static TerminalBlock from(StreamSource source, @NotNull PsiStatement body) {
return new TerminalBlock(source, source.myVariable, body).extractOperations();
}
}
@@ -0,0 +1,14 @@
// "Replace with forEach" "false"
import java.awt.*;
import java.util.List;
public class Main {
public void test(List<String> list) {
for(String s : li<caret>st) {
if(s == null)
}
System.out.println(s);
}
}
}