Index: org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java =================================================================== --- org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java (revision 156) +++ org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java (working copy) @@ -96,6 +96,7 @@ continueLabel, scope); UnconditionalFlowInfo actionInfo = condInfo.nullInfoLessUnconditionalCopy(); + actionInfo.markAsDefinitelyUnknown(this.elementVariable.binding); FlowInfo exitBranch; if (!(action == null || (action.isEmptyBlock() && currentScope.compilerOptions().complianceLevel <= ClassFileConstants.JDK1_3))) { Index: org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java =================================================================== --- org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (revision 156) +++ org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (working copy) @@ -6490,7 +6490,7 @@ // suggested by https://bugs.eclipse.org/bugs/show_bug.cgi?id=127570 // the issue is that we cannot do less than full aliasing analysis to // catch this one -// TODO (maxime) reconsider when/if we bring full aliasing in +// PREMATURE (maxime) reconsider when/if we bring full aliasing in public void _test0738_for_unknown_protection() { this.runConformTest( new String[] { @@ -6515,6 +6515,31 @@ ""); } +// null analysis -- for +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=178895 +public void test0739_for() { + if (COMPLIANCE_1_5.compareTo(this.complianceLevel) <= 0) { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " void foo(List l, boolean b) {\n" + + " for (Object o : l) {\n" + + " if (b) {\n" + + " if (o != null) {\n" + + " return;\n" + + " }\n" + + " } else {\n" + + " o.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); + } +} + // null analysis -- switch public void test0800_switch() { this.runConformTest(