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

(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (+98 lines)
Lines 34-39 Link Here
34
  	static {
34
  	static {
35
//    	TESTS_NAMES = new String[] { "test011" };
35
//    	TESTS_NAMES = new String[] { "test011" };
36
//    	TESTS_NUMBERS = new int[] { 516 };   
36
//    	TESTS_NUMBERS = new int[] { 516 };   
37
//    	TESTS_NUMBERS = new int[] { 732 };   
37
//    	TESTS_NUMBERS = new int[] { 2999 };   
38
//    	TESTS_NUMBERS = new int[] { 2999 };   
38
//    	TESTS_RANGE = new int[] { 2050, -1 }; 
39
//    	TESTS_RANGE = new int[] { 2050, -1 }; 
39
//  	TESTS_RANGE = new int[] { 1, 2049 }; 
40
//  	TESTS_RANGE = new int[] { 1, 2049 }; 
Lines 5300-5305 Link Here
5300
		"----------\n");
5301
		"----------\n");
5301
}
5302
}
5302
5303
5304
// null analysis - for nested with break
5305
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=129371
5306
public void test0732_for_nested_break() {
5307
	this.runConformTest(
5308
		new String[] {
5309
			"X.java",
5310
			"public class X {\n" + 
5311
			"  void foo(String doubt) {\n" + 
5312
			"    for(int i = 0; i < 10; i++) {\n" + 
5313
			"      String s = doubt;\n" + 
5314
			"      if(s != null) {\n" + 
5315
			"        for(int j = 0; j < 1; j++) {\n" + 
5316
			"          break;\n" + 
5317
			"        }\n" + 
5318
			"        s.length();\n" + 
5319
			"      }\n" + 
5320
			"    }\n" + 
5321
			"  }\n" + 
5322
			"}\n" + 
5323
			"\n"},
5324
		"");
5325
}
5326
5327
// null analysis - for while with break
5328
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=129371
5329
// variant
5330
public void test0733_for_while_break() {
5331
	this.runConformTest(
5332
		new String[] {
5333
			"X.java",
5334
			"public class X {\n" + 
5335
			"  void foo(String doubt, boolean b) {\n" + 
5336
			"    for(int i = 0; i < 10; i++) {\n" + 
5337
			"      String s = doubt;\n" + 
5338
			"      if (s != null) {\n" + 
5339
			"        while (b) {\n" + 
5340
			"          break;\n" + 
5341
			"        }\n" + 
5342
			"        s.length();\n" + 
5343
			"      }\n" + 
5344
			"    }\n" + 
5345
			"  }\n" + 
5346
			"}\n" + 
5347
			"\n"},
5348
		"");
5349
}
5350
5351
// null analysis - for while with break
5352
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=129371
5353
// variant
5354
public void test0734_for_while_break() {
5355
	this.runConformTest(
5356
		new String[] {
5357
			"X.java",
5358
			"public class X {\n" + 
5359
			"  void foo(String doubt, boolean b) {\n" + 
5360
			"    for(int i = 0; i < 10; i++) {\n" + 
5361
			"      String s = doubt;\n" + 
5362
			"      if (s != null) {\n" + 
5363
			"        do {\n" + 
5364
			"          break;\n" + 
5365
			"        } while (b);\n" + 
5366
			"        s.length();\n" + 
5367
			"      }\n" + 
5368
			"    }\n" + 
5369
			"  }\n" + 
5370
			"}\n" + 
5371
			"\n"},
5372
		"");
5373
}
5374
5375
// null analysis - for nested with break
5376
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=129371
5377
// variant
5378
public void test0735_for_nested_break() {
5379
	if (COMPLIANCE_1_5.equals(this.complianceLevel)) {
5380
		this.runConformTest(
5381
			new String[] {
5382
				"X.java",
5383
				"public class X {\n" + 
5384
				"  void foo(Object[] a, String doubt) {\n" + 
5385
				"    for(int i = 0; i < 10; i++) {\n" + 
5386
				"      String s = doubt;\n" + 
5387
				"      if(s != null) {\n" + 
5388
				"        for(Object o : a) {\n" + 
5389
				"          break;\n" + 
5390
				"        }\n" + 
5391
				"        s.length();\n" + 
5392
				"      }\n" + 
5393
				"    }\n" + 
5394
				"  }\n" + 
5395
				"}\n" + 
5396
				"\n"},
5397
			"");
5398
	}
5399
}
5400
5303
// null analysis -- switch
5401
// null analysis -- switch
5304
public void test0800_switch() {
5402
public void test0800_switch() {
5305
	this.runConformTest(
5403
	this.runConformTest(
(-)compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java (-1 / +4 lines)
Lines 143-149 Link Here
143
143
144
		// end of loop
144
		// end of loop
145
		FlowInfo mergedInfo = FlowInfo.mergedOptimizedBranches(
145
		FlowInfo mergedInfo = FlowInfo.mergedOptimizedBranches(
146
				loopingContext.initsOnBreak, 
146
				(loopingContext.initsOnBreak.tagBits &
147
					FlowInfo.UNREACHABLE) != 0 ?
148
					loopingContext.initsOnBreak :
149
					flowInfo.addInitializationsFrom(loopingContext.initsOnBreak), // recover upstream null info
147
				isConditionOptimizedTrue, 
150
				isConditionOptimizedTrue, 
148
				exitBranch,
151
				exitBranch,
149
				isConditionOptimizedFalse,
152
				isConditionOptimizedFalse,
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java (-1 / +4 lines)
Lines 193-199 Link Here
193
193
194
		//end of loop
194
		//end of loop
195
		FlowInfo mergedInfo = FlowInfo.mergedOptimizedBranches(
195
		FlowInfo mergedInfo = FlowInfo.mergedOptimizedBranches(
196
				loopingContext.initsOnBreak, 
196
				(loopingContext.initsOnBreak.tagBits &
197
					FlowInfo.UNREACHABLE) != 0 ?
198
					loopingContext.initsOnBreak :
199
					flowInfo.addInitializationsFrom(loopingContext.initsOnBreak), // recover upstream null info
197
				isConditionOptimizedTrue, 
200
				isConditionOptimizedTrue, 
198
				exitBranch, 
201
				exitBranch, 
199
				isConditionOptimizedFalse, 
202
				isConditionOptimizedFalse, 
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java (-1 / +4 lines)
Lines 143-149 Link Here
143
		loopingContext.complainOnDeferredNullChecks(currentScope, actionInfo);
143
		loopingContext.complainOnDeferredNullChecks(currentScope, actionInfo);
144
144
145
		FlowInfo mergedInfo = FlowInfo.mergedOptimizedBranches(
145
		FlowInfo mergedInfo = FlowInfo.mergedOptimizedBranches(
146
				loopingContext.initsOnBreak, 
146
				(loopingContext.initsOnBreak.tagBits &
147
					FlowInfo.UNREACHABLE) != 0 ?
148
					loopingContext.initsOnBreak :
149
					flowInfo.addInitializationsFrom(loopingContext.initsOnBreak), // recover upstream null info
147
				false, 
150
				false, 
148
				exitBranch, 
151
				exitBranch, 
149
				false, 
152
				false, 
(-)compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java (-1 / +4 lines)
Lines 107-113 Link Here
107
107
108
		// end of loop
108
		// end of loop
109
		FlowInfo mergedInfo = FlowInfo.mergedOptimizedBranches(
109
		FlowInfo mergedInfo = FlowInfo.mergedOptimizedBranches(
110
				loopingContext.initsOnBreak, 
110
				(loopingContext.initsOnBreak.tagBits &
111
					FlowInfo.UNREACHABLE) != 0 ?
112
					loopingContext.initsOnBreak :
113
					flowInfo.addInitializationsFrom(loopingContext.initsOnBreak), // recover upstream null info
111
				isConditionOptimizedTrue,
114
				isConditionOptimizedTrue,
112
				(condInfo.tagBits & FlowInfo.UNREACHABLE) == 0 ?
115
				(condInfo.tagBits & FlowInfo.UNREACHABLE) == 0 ?
113
						flowInfo.addInitializationsFrom(condInfo.initsWhenFalse()) : condInfo, 
116
						flowInfo.addInitializationsFrom(condInfo.initsWhenFalse()) : condInfo, 

Return to bug 129371