View | Details | Raw Unified | Return to bug 166641
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java (-1 / +88 lines)
Lines 1122-1128 Link Here
1122
	}
1122
	}
1123
}
1123
}
1124
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641
1124
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641
1125
public void _test037() {
1125
public void test037() {
1126
	this.runNegativeTest(
1126
	this.runNegativeTest(
1127
		new String[] {
1127
		new String[] {
1128
			"X.java",
1128
			"X.java",
Lines 1159-1164 Link Here
1159
		},
1159
		},
1160
		"");
1160
		"");
1161
}
1161
}
1162
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641
1163
// variant with deeper nesting
1164
public void test039() {
1165
	this.runNegativeTest(
1166
		new String[] {
1167
			"X.java",
1168
			"public class X {\n" + 
1169
			"  void foo() {\n" + 
1170
			"    if (false) {\n" + 
1171
			"      String s;\n" + 
1172
			"      if (System.out != null) {\n" +
1173
			"        System.out.println(s);\n" +
1174
			"      }\n" + 
1175
			"    }\n" + 
1176
			"  }\n" + 
1177
			"}"
1178
		},
1179
		"----------\n" + 
1180
		"1. ERROR in X.java (at line 6)\n" + 
1181
		"	System.out.println(s);\n" + 
1182
		"	                   ^\n" + 
1183
		"The local variable s may not have been initialized\n" + 
1184
		"----------\n");
1185
}
1186
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641
1187
// variant - checking duplicate initialization of final variables
1188
public void test040() {
1189
	this.runNegativeTest(
1190
		new String[] {
1191
			"X.java",
1192
			"public class X {\n" + 
1193
			"  void foo() {\n" + 
1194
			"    final String s = \"\";\n" + 
1195
			"    if (false) {\n" + 
1196
			"      s = \"\";\n" + 
1197
			"    }\n" + 
1198
			"  }\n" + 
1199
			"}"
1200
		},
1201
		"----------\n" + 
1202
		"1. ERROR in X.java (at line 5)\n" + 
1203
		"	s = \"\";\n" + 
1204
		"	^\n" + 
1205
		"The final local variable s cannot be assigned. It must be blank and not using a compound assignment\n" + 
1206
		"----------\n");
1207
}
1208
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641
1209
// variant - checking duplicate initialization of final variables
1210
public void test041() {
1211
	this.runConformTest(
1212
		new String[] {
1213
			"X.java",
1214
			"public class X {\n" + 
1215
			"  void foo() {\n" + 
1216
			"    final String s;\n" + 
1217
			"    s = \"\";\n" + 
1218
			"    if (false) {\n" + 
1219
			"      s = \"\";\n" + 
1220
			"    }\n" + 
1221
			"  }\n" + 
1222
			"}"
1223
		},
1224
		"");
1225
}
1226
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641
1227
// variant - checking duplicate initialization of final variables
1228
public void test042() {
1229
	this.runNegativeTest(
1230
		new String[] {
1231
			"X.java",
1232
			"public class X {\n" + 
1233
			"  void foo() {\n" + 
1234
			"    final String s;\n" + 
1235
			"    if (false) {\n" + 
1236
			"      s = \"\";\n" + 
1237
			"    }\n" + 
1238
			"    s = \"\";\n" + 
1239
			"  }\n" + 
1240
			"}"
1241
		},
1242
		"----------\n" + 
1243
		"1. ERROR in X.java (at line 7)\n" + 
1244
		"	s = \"\";\n" + 
1245
		"	^\n" + 
1246
		"The final local variable s may already have been assigned\n" + 
1247
		"----------\n");
1248
}
1162
public static Class testClass() {
1249
public static Class testClass() {
1163
	return FlowAnalysisTest.class;
1250
	return FlowAnalysisTest.class;
1164
}
1251
}
(-)compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java (-2 / +3 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.flow;
11
package org.eclipse.jdt.internal.compiler.flow;
12
12
13
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
13
import org.eclipse.jdt.internal.compiler.impl.Constant;
14
import org.eclipse.jdt.internal.compiler.impl.Constant;
14
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
15
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
15
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
16
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
Lines 692-699 Link Here
692
}
693
}
693
694
694
final public boolean isDefinitelyAssigned(LocalVariableBinding local) {
695
final public boolean isDefinitelyAssigned(LocalVariableBinding local) {
695
	// do not want to complain in unreachable code
696
	// do not want to complain in unreachable code if local declared in reachable code
696
	if ((this.tagBits & UNREACHABLE) != 0) {
697
	if ((this.tagBits & UNREACHABLE) != 0 && (local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0) {
697
		return true;
698
		return true;
698
	}
699
	}
699
	return isDefinitelyAssigned(local.id + this.maxFieldCount);
700
	return isDefinitelyAssigned(local.id + this.maxFieldCount);

Return to bug 166641