### Eclipse Workspace Patch 1.0 #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.58 diff -u -r1.58 UnconditionalFlowInfo.java --- compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java 26 Sep 2006 12:04:03 -0000 1.58 +++ compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java 10 Nov 2006 15:04:13 -0000 @@ -696,10 +696,6 @@ if ((this.tagBits & UNREACHABLE) != 0) { return true; } - // final constants are inlined, and thus considered as always initialized - if (local.constant() != Constant.NotAConstant) { - return true; - } return isDefinitelyAssigned(local.id + this.maxFieldCount); } Index: compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java,v retrieving revision 1.91 diff -u -r1.91 SingleNameReference.java --- compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 13 Oct 2006 19:20:46 -0000 1.91 +++ compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 10 Nov 2006 15:04:12 -0000 @@ -160,7 +160,10 @@ break; case Binding.LOCAL : // reading a local variable LocalVariableBinding localBinding; - if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) binding)) { + if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) binding) && + !(localBinding.constant() != Constant.NotAConstant && + currentScope.compilerOptions().complianceLevel <= ClassFileConstants.JDK1_3)) { + // up to JDK 1.3 included, final constants are inlined, and thus considered as always initialized currentScope.problemReporter().uninitializedLocalVariable(localBinding, this); } if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 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.16 diff -u -r1.16 FlowAnalysisTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java 9 Nov 2006 11:07:10 -0000 1.16 +++ src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java 10 Nov 2006 15:04:15 -0000 @@ -1032,24 +1032,43 @@ ""); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162918 -public void _test034() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo1() {\n" + - " switch (1) {\n" + - " case 0:\n" + - " final int i = 1;\n" + - " case i: // should complain: i not initialized\n" + - " System.out.println(i); // should complain: i not initialized\n" + - " }\n" + - " }\n" + - "}", - }, - "----------\n" + - "2 ERRORS" + - "----------\n"); +public void test034() { + String src = + "public class X {\n" + + " void foo1() {\n" + + " switch (1) {\n" + + " case 0:\n" + + " final int i = 1;\n" + + " case i: // should complain: i not initialized\n" + + " System.out.println(i); // should complain: i not initialized\n" + + " }\n" + + " }\n" + + "}"; + if (complianceLevel.compareTo(COMPLIANCE_1_3) <= 0) { + this.runConformTest( + new String[] { + "X.java", + src + }, + ""); + } else { + this.runNegativeTest( + new String[] { + "X.java", + src + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case i: // should complain: i not initialized\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " System.out.println(i); // should complain: i not initialized\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n"); + } } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162918 // variant @@ -1076,30 +1095,42 @@ "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162918 -// variant -public void _test036() { - this.runNegativeTest( - new String[] { - "X.java", - "public class X {\n" + - " void foo3() {\n" + - " switch (1) {\n" + - " case 0:\n" + - " class Local {\n" + - " }\n" + - " ;\n" + - " case 1:\n" + - " new Local(); // should complain: Local undefined\n" + - " }\n" + - " }\n" + - "}", - }, - "----------\n" + - "1. ERROR in X.java (at line 9)\n" + - " new Local(); // should complain: Local undefined\n" + - " ^^^^^\n" + - "Local cannot be resolved to a type\n" + - "----------\n"); +// variant - not a flow analysis issue per se, contrast with 34 and 35 above +public void test036() { + String src = + "public class X {\n" + + " void foo3() {\n" + + " switch (1) {\n" + + " case 0:\n" + + " class Local {\n" + + " }\n" + + " ;\n" + + " case 1:\n" + + " new Local();\n" + // complain for compliance >= 1.4 + " }\n" + + " }\n" + + "}"; + if (complianceLevel.compareTo(COMPLIANCE_1_3) <= 0) { + this.runConformTest( + new String[] { + "X.java", + src + }, + "" + ); + } else { + this.runNegativeTest( + new String[] { + "X.java", + src + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " new Local();\n" + + " ^^^^^\n" + + "Local cannot be resolved to a type\n" + + "----------\n"); + } } public static Class testClass() { return FlowAnalysisTest.class;