diff options
| author | Stephan Herrmann | 2012-05-29 14:24:31 +0000 |
|---|---|---|
| committer | Jayaprakash Arthanareeswaran | 2013-01-01 14:58:03 +0000 |
| commit | cc6afd2780e30da42e933d85be2a5b149ab2948a (patch) | |
| tree | 543d5d426312a618f2f2d5e8119d4dbfa4aead7d | |
| parent | 2d77ae6250b9fb38d19c6ba07f99c88fa5be8b9a (diff) | |
| download | eclipse.jdt.core-cc6afd2780e30da42e933d85be2a5b149ab2948a.tar.gz eclipse.jdt.core-cc6afd2780e30da42e933d85be2a5b149ab2948a.tar.xz eclipse.jdt.core-cc6afd2780e30da42e933d85be2a5b149ab2948a.zip | |
Fixed bug 380750: [compiler] local incorrectly flagged as uninitialized
due to fix for bug 359495
2 files changed, 25 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java index 2e6883fda4..7605b435c4 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java @@ -2443,6 +2443,29 @@ public void testBug380313b() { }, ""); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=380750 +// verify that s0 is not reported as uninitialized +public void testBug380750() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(String[] args) {\n" + + " String s0;\n" + + " for(String s : singleton(s0=\"\")) {\n" + + " System.out.println(s);\n" + + " }\n" + + " System.out.println(s0);\n" + + " }\n" + + " String[] singleton(String s) {\n" + + " return new String[] {s};\n" + + " }\n" + + "}\n" + }, + ""); +} public static Class testClass() { return FlowAnalysisTest.class; } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java index 28be3c5cb4..b6f6ba5891 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java @@ -105,7 +105,7 @@ public class ForeachStatement extends Statement { // code generation can be optimized when no need to continue in the loop exitBranch = flowInfo.unconditionalCopy(). - addNullInfoFrom(condInfo.initsWhenFalse()); + addInitializationsFrom(condInfo.initsWhenFalse()); // TODO (maxime) no need to test when false: can optimize (same for action being unreachable above) if ((actionInfo.tagBits & loopingContext.initsOnContinue.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0) { @@ -153,6 +153,7 @@ public class ForeachStatement extends Statement { exitBranch, false, true /*for(;;){}while(true); unreachable(); */); + mergedInfo.resetAssignmentInfo(this.elementVariable.binding); this.mergedInitStateIndex = currentScope.methodScope().recordInitializationStates(mergedInfo); return mergedInfo; } |
