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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java (+71 lines)
Lines 1361-1366 Link Here
1361
		},
1361
		},
1362
		"");
1362
		"");
1363
}
1363
}
1364
// labeled loop
1365
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200158
1366
// contrast this with test049
1367
public void test048() {
1368
	runTest(
1369
		new String[] {
1370
			"X.java",
1371
			"public class X {\n" + 
1372
			"  private static final boolean b = false;\n" + 
1373
			"  public Object foo() {\n" + 
1374
			"    if (b) {\n" + 
1375
			"      label: while (bar()) {\n" + 
1376
			"      }\n" + 
1377
			"      return null;\n" + 
1378
			"    }\n" + 
1379
			"    return null;\n" + 
1380
			"  }\n" + 
1381
			"  boolean bar() {\n" + 
1382
			"    return false;\n" + 
1383
			"  }\n" + 
1384
			"}\n"
1385
			},
1386
		false /* expectingCompilerErrors */,
1387
		"----------\n" + 
1388
		"1. WARNING in X.java (at line 5)\n" + 
1389
		"	label: while (bar()) {\n" + 
1390
		"	^^^^^\n" + 
1391
		"The label label is never explicitly referenced\n" + 
1392
		"----------\n" /* expectedCompilerLog */,
1393
		"" /* expectedOutputString */,
1394
		false /* forceExecution */,
1395
		null /* classLib */,
1396
		true /* shouldFlushOutputDirectory */, 
1397
		null /* vmArguments */, 
1398
		null /* customOptions */,
1399
		null /* clientRequestor */,
1400
		true /* skipJavac */);
1401
}
1402
// labeled loop
1403
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200158
1404
// variant: this one passes
1405
public void test049() {
1406
	runTest(
1407
		new String[] {
1408
			"X.java",
1409
			"public class X {\n" + 
1410
			"  private static final boolean b = false;\n" + 
1411
			"  public Object foo() {\n" + 
1412
			"    if (b) {\n" + 
1413
			"      while (bar()) {\n" + 
1414
			"      }\n" + 
1415
			"      return null;\n" + 
1416
			"    }\n" + 
1417
			"    return null;\n" + 
1418
			"  }\n" + 
1419
			"  boolean bar() {\n" + 
1420
			"    return false;\n" + 
1421
			"  }\n" + 
1422
			"}\n"
1423
			},
1424
		false /* expectingCompilerErrors */,
1425
		"" /* expectedCompilerLog */,
1426
		"" /* expectedOutputString */,
1427
		false /* forceExecution */,
1428
		null /* classLib */,
1429
		true /* shouldFlushOutputDirectory */, 
1430
		null /* vmArguments */, 
1431
		null /* customOptions */,
1432
		null /* clientRequestor */,
1433
		true /* skipJavac */);
1434
}
1364
public static Class testClass() {
1435
public static Class testClass() {
1365
	return FlowAnalysisTest.class;
1436
	return FlowAnalysisTest.class;
1366
}
1437
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java (-4 / +132 lines)
Lines 229-237 Link Here
229
		}
229
		}
230
	}
230
	}
231
231
232
	/*######################################
233
	 * Specific method to let tests Sun javac compilation available...
234
	 #######################################*/
235
	protected void compileAndDeploy(String source, String directoryName, String className) {
232
	protected void compileAndDeploy(String source, String directoryName, String className) {
236
		File directory = new File(SOURCE_DIRECTORY);
233
		File directory = new File(SOURCE_DIRECTORY);
237
		if (!directory.exists()) {
234
		if (!directory.exists()) {
Lines 266-273 Link Here
266
			.append(EVAL_DIRECTORY);
263
			.append(EVAL_DIRECTORY);
267
		if (this.complianceLevel.compareTo(COMPLIANCE_1_5) < 0) {
264
		if (this.complianceLevel.compareTo(COMPLIANCE_1_5) < 0) {
268
			buffer.append("\" -1.4 -source 1.3 -target 1.2");
265
			buffer.append("\" -1.4 -source 1.3 -target 1.2");
269
		} else {
266
		} else if (this.complianceLevel.compareTo(COMPLIANCE_1_5) == 0) {
270
			buffer.append("\" -1.5");
267
			buffer.append("\" -1.5");
268
		} else if (this.complianceLevel.compareTo(COMPLIANCE_1_6) == 0) {
269
			buffer.append("\" -1.6");
270
		} else if (this.complianceLevel.compareTo(COMPLIANCE_1_7) == 0) {
271
			buffer.append("\" -1.7");
271
		}
272
		}
272
		buffer
273
		buffer
273
			.append(" -preserveAllLocals -nowarn -g -classpath \"")
274
			.append(" -preserveAllLocals -nowarn -g -classpath \"")
Lines 1243-1248 Link Here
1243
		}
1244
		}
1244
	}
1245
	}
1245
1246
1247
	protected void runTest(
1248
			String[] testFiles,
1249
			boolean expectingCompilerErrors,
1250
			String expectedCompilerLog,
1251
			String expectedOutputString,
1252
			boolean forceExecution,
1253
			String[] classLib,
1254
			boolean shouldFlushOutputDirectory, 
1255
			String[] vmArguments, 
1256
			Map customOptions,
1257
			ICompilerRequestor clientRequestor,
1258
			boolean skipJavac) {
1259
		// Non-javac part
1260
		try {
1261
			if (shouldFlushOutputDirectory)
1262
				Util.flushDirectoryContent(new File(OUTPUT_DIR));
1263
	
1264
			IProblemFactory problemFactory = getProblemFactory();
1265
			Requestor requestor = 
1266
				new Requestor(
1267
					problemFactory, 
1268
					OUTPUT_DIR.endsWith(File.separator) ? OUTPUT_DIR : OUTPUT_DIR + File.separator, 
1269
					forceExecution,
1270
					clientRequestor,
1271
					false, /* show category */
1272
					false /* show warning token*/);
1273
	
1274
			Map options = getCompilerOptions();
1275
			if (customOptions != null) {
1276
				options.putAll(customOptions);
1277
			}
1278
			CompilerOptions compilerOptions = new CompilerOptions(options);
1279
			compilerOptions.performMethodsFullRecovery = false;
1280
			compilerOptions.performStatementsRecovery = false;
1281
			Compiler batchCompiler = 
1282
				new Compiler(
1283
					getNameEnvironment(new String[]{}, classLib), 
1284
					getErrorHandlingPolicy(), 
1285
					compilerOptions,
1286
					requestor, 
1287
					problemFactory);
1288
			compilerOptions.produceReferenceInfo = true;
1289
			Throwable exception = null;
1290
			try {
1291
				batchCompiler.compile(Util.compilationUnits(testFiles)); // compile all files together
1292
			} catch(RuntimeException e){
1293
				exception = e;
1294
				throw e;
1295
			} catch(Error e) {
1296
				exception = e;
1297
				throw e;
1298
			} finally {
1299
				String computedProblemLog = Util.convertToIndependantLineDelimiter(requestor.problemLog.toString());
1300
				String platformIndependantExpectedLog = Util.convertToIndependantLineDelimiter(expectedCompilerLog);
1301
				if (!platformIndependantExpectedLog.equals(computedProblemLog)) {
1302
					System.out.println(getClass().getName() + '#' + getName());
1303
					System.out.println(Util.displayString(computedProblemLog, INDENT, SHIFT));
1304
					for (int i = 0; i < testFiles.length; i += 2) {
1305
						System.out.print(testFiles[i]);
1306
						System.out.println(" ["); //$NON-NLS-1$
1307
						System.out.println(testFiles[i + 1]);
1308
						System.out.println("]"); //$NON-NLS-1$
1309
					}
1310
				}
1311
				if (exception == null) {
1312
					if (expectingCompilerErrors) {
1313
						assertTrue("Unexpected success", requestor.hasErrors);
1314
					} else {
1315
						assertFalse("Unexpected failure", requestor.hasErrors);
1316
					}
1317
					assertEquals("Invalid problem log ", platformIndependantExpectedLog, computedProblemLog);
1318
				}
1319
			}
1320
			if (!requestor.hasErrors || forceExecution) {
1321
				String sourceFile = testFiles[0];
1322
	
1323
				// Compute class name by removing ".java" and replacing slashes with dots
1324
				String className = sourceFile.substring(0, sourceFile.length() - 5).replace('/', '.').replace('\\', '.');
1325
				if (className.endsWith(PACKAGE_INFO_NAME)) return;
1326
	
1327
				if (vmArguments != null) {
1328
					if (this.verifier != null) {
1329
						this.verifier.shutDown();
1330
					}
1331
					this.verifier = new TestVerifier(false);
1332
					this.createdVerifier = true;
1333
				}
1334
				boolean passed = 
1335
					this.verifier.verifyClassFiles(
1336
						sourceFile, 
1337
						className, 
1338
						expectedOutputString,
1339
						this.classpaths, 
1340
						null, 
1341
						vmArguments);
1342
				if (!passed) {
1343
					System.out.println(getClass().getName() + '#' + getName());
1344
					for (int i = 0; i < testFiles.length; i += 2) {
1345
						System.out.print(testFiles[i]);
1346
						System.out.println(" ["); //$NON-NLS-1$
1347
						System.out.println(testFiles[i + 1]);
1348
						System.out.println("]"); //$NON-NLS-1$
1349
					}
1350
				}
1351
				assertTrue(this.verifier.failureReason, // computed by verifyClassFiles(...) action
1352
						passed);
1353
				if (vmArguments != null) {
1354
					if (this.verifier != null) {
1355
						this.verifier.shutDown();
1356
					}
1357
					this.verifier = new TestVerifier(false);
1358
					this.createdVerifier = true;
1359
				}
1360
			}
1361
		// javac part
1362
		} catch (AssertionFailedError e) {
1363
			throw e;
1364
		} finally {
1365
			if (RUN_JAVAC && !skipJavac)
1366
				runJavac(testFiles, null, expectedOutputString, shouldFlushOutputDirectory);
1367
			  // PREMATURE for now, skipping javac implies skipping the compile
1368
			  //                and execution steps; yet, only cases for which the
1369
			  //                execution step was a problem have been discovered so
1370
			  //                far; may consider skipping the execution step only
1371
		}
1372
	}
1373
1246
	protected void setUp() throws Exception {
1374
	protected void setUp() throws Exception {
1247
		super.setUp();
1375
		super.setUp();
1248
		if (this.verifier == null) {
1376
		if (this.verifier == null) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/LabeledStatement.java (-20 / +17 lines)
Lines 51-76 Link Here
51
		} else {
51
		} else {
52
			LabelFlowContext labelContext;
52
			LabelFlowContext labelContext;
53
			FlowInfo statementInfo, mergedInfo;
53
			FlowInfo statementInfo, mergedInfo;
54
			if (((statementInfo = statement
54
			statementInfo = statement.analyseCode(
55
					.analyseCode(
55
				currentScope,
56
						currentScope,
56
				(labelContext =
57
						(labelContext =
57
					new LabelFlowContext(
58
							new LabelFlowContext(
58
						flowContext,
59
								flowContext,
59
						this,
60
								this,
60
						label,
61
								label,
61
						(targetLabel = new BranchLabel()),
62
								(targetLabel = new BranchLabel()),
62
						currentScope)),
63
								currentScope)),
63
				flowInfo);
64
						flowInfo)).tagBits & FlowInfo.UNREACHABLE) != 0) {
64
			boolean reinjectNullInfo = (statementInfo.tagBits & FlowInfo.UNREACHABLE) != 0 &&
65
				if ((labelContext.initsOnBreak.tagBits & FlowInfo.UNREACHABLE) == 0) {
65
				(labelContext.initsOnBreak.tagBits & FlowInfo.UNREACHABLE) == 0;
66
					// an embedded loop has had no chance to reinject forgotten null info
66
			mergedInfo = statementInfo.mergedWith(labelContext.initsOnBreak);
67
					mergedInfo = flowInfo.unconditionalCopy().
67
			if (reinjectNullInfo) {
68
						addInitializationsFrom(labelContext.initsOnBreak);
68
				// an embedded loop has had no chance to reinject forgotten null info
69
				} else {
69
				((UnconditionalFlowInfo)mergedInfo).addInitializationsFrom(flowInfo.unconditionalFieldLessCopy()).
70
					mergedInfo = labelContext.initsOnBreak;
70
					addInitializationsFrom(labelContext.initsOnBreak.unconditionalFieldLessCopy());
71
				}
72
			} else {
73
				mergedInfo = statementInfo.mergedWith(labelContext.initsOnBreak);
74
			}
71
			}
75
			mergedInitStateIndex =
72
			mergedInitStateIndex =
76
				currentScope.methodScope().recordInitializationStates(mergedInfo);
73
				currentScope.methodScope().recordInitializationStates(mergedInfo);

Return to bug 200158