### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java,v retrieving revision 1.18 diff -u -r1.18 FlowAnalysisTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java 5 Dec 2006 09:15:41 -0000 1.18 +++ src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java 5 Dec 2006 09:37:07 -0000 @@ -1122,7 +1122,7 @@ } } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641 -public void _test037() { +public void test037() { this.runNegativeTest( new String[] { "X.java", @@ -1159,6 +1159,93 @@ }, ""); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641 +// variant with deeper nesting +public void test039() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " if (false) {\n" + + " String s;\n" + + " if (System.out != null) {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " System.out.println(s);\n" + + " ^\n" + + "The local variable s may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641 +// variant - checking duplicate initialization of final variables +public void test040() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " final String s = \"\";\n" + + " if (false) {\n" + + " s = \"\";\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " s = \"\";\n" + + " ^\n" + + "The final local variable s cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641 +// variant - checking duplicate initialization of final variables +public void test041() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " final String s;\n" + + " s = \"\";\n" + + " if (false) {\n" + + " s = \"\";\n" + + " }\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641 +// variant - checking duplicate initialization of final variables +public void test042() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " final String s;\n" + + " if (false) {\n" + + " s = \"\";\n" + + " }\n" + + " s = \"\";\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " s = \"\";\n" + + " ^\n" + + "The final local variable s may already have been assigned\n" + + "----------\n"); +} public static Class testClass() { return FlowAnalysisTest.class; } #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java,v retrieving revision 1.59 diff -u -r1.59 UnconditionalFlowInfo.java --- compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java 13 Nov 2006 05:36:40 -0000 1.59 +++ compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java 5 Dec 2006 09:37:10 -0000 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.jdt.internal.compiler.flow; +import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.impl.Constant; import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; @@ -692,8 +693,8 @@ } final public boolean isDefinitelyAssigned(LocalVariableBinding local) { - // do not want to complain in unreachable code - if ((this.tagBits & UNREACHABLE) != 0) { + // do not want to complain in unreachable code if local declared in reachable code + if ((this.tagBits & UNREACHABLE) != 0 && (local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0) { return true; } return isDefinitelyAssigned(local.id + this.maxFieldCount);