View | Details | Raw Unified | Return to bug 162918 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java (-4 lines)
Lines 696-705 Link Here
696
	if ((this.tagBits & UNREACHABLE) != 0) {
696
	if ((this.tagBits & UNREACHABLE) != 0) {
697
		return true;
697
		return true;
698
	}
698
	}
699
	// final constants are inlined, and thus considered as always initialized
700
	if (local.constant() != Constant.NotAConstant) {
701
		return true;
702
	}
703
	return isDefinitelyAssigned(local.id + this.maxFieldCount);
699
	return isDefinitelyAssigned(local.id + this.maxFieldCount);
704
}
700
}
705
701
(-)compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java (-1 / +4 lines)
Lines 160-166 Link Here
160
				break;
160
				break;
161
			case Binding.LOCAL : // reading a local variable
161
			case Binding.LOCAL : // reading a local variable
162
				LocalVariableBinding localBinding;
162
				LocalVariableBinding localBinding;
163
				if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) binding)) {
163
				if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) binding) &&
164
						!(localBinding.constant() != Constant.NotAConstant && 
165
								currentScope.compilerOptions().complianceLevel <= ClassFileConstants.JDK1_3)) {
166
					// up to JDK 1.3 included, final constants are inlined, and thus considered as always initialized
164
					currentScope.problemReporter().uninitializedLocalVariable(localBinding, this);
167
					currentScope.problemReporter().uninitializedLocalVariable(localBinding, this);
165
				}
168
				}
166
				if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)	{
169
				if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)	{
(-)src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java (-42 / +73 lines)
Lines 1032-1055 Link Here
1032
		"");
1032
		"");
1033
}
1033
}
1034
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162918
1034
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162918
1035
public void _test034() {
1035
public void test034() {
1036
	this.runNegativeTest(
1036
	String src =
1037
		new String[] {
1037
		"public class X {\n" + 
1038
			"X.java",
1038
		"  void foo1() {\n" + 
1039
			"public class X {\n" + 
1039
		"    switch (1) {\n" + 
1040
			"  void foo1() {\n" + 
1040
		"    case 0:\n" + 
1041
			"    switch (1) {\n" + 
1041
		"      final int i = 1;\n" + 
1042
			"    case 0:\n" + 
1042
		"    case i: // should complain: i not initialized\n" + 
1043
			"      final int i = 1;\n" + 
1043
		"      System.out.println(i); // should complain: i not initialized\n" + 
1044
			"    case i: // should complain: i not initialized\n" + 
1044
		"    }\n" + 
1045
			"      System.out.println(i); // should complain: i not initialized\n" + 
1045
		"  }\n" + 
1046
			"    }\n" + 
1046
		"}";
1047
			"  }\n" + 
1047
	if (complianceLevel.compareTo(COMPLIANCE_1_3) <= 0) {
1048
			"}",
1048
		this.runConformTest(
1049
		},
1049
			new String[] {
1050
		"----------\n" + 
1050
				"X.java",
1051
		"2 ERRORS" + 
1051
				src
1052
		"----------\n");
1052
			},
1053
			"");
1054
	} else {
1055
		this.runNegativeTest(
1056
			new String[] {
1057
				"X.java",
1058
				src
1059
			},
1060
			"----------\n" + 
1061
			"1. ERROR in X.java (at line 6)\n" + 
1062
			"	case i: // should complain: i not initialized\n" + 
1063
			"	     ^\n" + 
1064
			"The local variable i may not have been initialized\n" + 
1065
			"----------\n" + 
1066
			"2. ERROR in X.java (at line 7)\n" + 
1067
			"	System.out.println(i); // should complain: i not initialized\n" + 
1068
			"	                   ^\n" + 
1069
			"The local variable i may not have been initialized\n" + 
1070
			"----------\n");
1071
	}
1053
}
1072
}
1054
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162918
1073
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162918
1055
// variant
1074
// variant
Lines 1076-1105 Link Here
1076
		"----------\n");
1095
		"----------\n");
1077
}
1096
}
1078
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162918
1097
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162918
1079
// variant
1098
// variant - not a flow analysis issue per se, contrast with 34 and 35 above
1080
public void _test036() {
1099
public void test036() {
1081
	this.runNegativeTest(
1100
	String src =
1082
		new String[] {
1101
		"public class X {\n" + 
1083
			"X.java",
1102
		"  void foo3() {\n" + 
1084
			"public class X {\n" + 
1103
		"    switch (1) {\n" + 
1085
			"  void foo3() {\n" + 
1104
		"    case 0:\n" + 
1086
			"    switch (1) {\n" + 
1105
		"      class Local {\n" + 
1087
			"    case 0:\n" + 
1106
		"      }\n" + 
1088
			"      class Local {\n" + 
1107
		"      ;\n" + 
1089
			"      }\n" + 
1108
		"    case 1:\n" + 
1090
			"      ;\n" + 
1109
		"      new Local();\n" +  // complain for compliance >= 1.4
1091
			"    case 1:\n" + 
1110
		"    }\n" + 
1092
			"      new Local(); // should complain: Local undefined\n" + 
1111
		"  }\n" + 
1093
			"    }\n" + 
1112
		"}";
1094
			"  }\n" + 
1113
	if (complianceLevel.compareTo(COMPLIANCE_1_3) <= 0) {
1095
			"}",
1114
		this.runConformTest(
1096
		},
1115
				new String[] {
1097
		"----------\n" + 
1116
					"X.java",
1098
		"1. ERROR in X.java (at line 9)\n" + 
1117
					src
1099
		"	new Local(); // should complain: Local undefined\n" + 
1118
				},
1100
		"	    ^^^^^\n" + 
1119
				""
1101
		"Local cannot be resolved to a type\n" + 
1120
			);
1102
		"----------\n");
1121
	} else {
1122
		this.runNegativeTest(
1123
			new String[] {
1124
				"X.java",
1125
				src
1126
			},
1127
			"----------\n" + 
1128
			"1. ERROR in X.java (at line 9)\n" + 
1129
			"	new Local();\n" + 
1130
			"	    ^^^^^\n" + 
1131
			"Local cannot be resolved to a type\n" + 
1132
			"----------\n");
1133
	}
1103
}
1134
}
1104
public static Class testClass() {
1135
public static Class testClass() {
1105
	return FlowAnalysisTest.class;
1136
	return FlowAnalysisTest.class;

Return to bug 162918