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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java (-5 / +22 lines)
Lines 32-37 Link Here
32
	private LoopingFlowContext innerFlowContexts[] = null;
32
	private LoopingFlowContext innerFlowContexts[] = null;
33
	private UnconditionalFlowInfo innerFlowInfos[] = null;
33
	private UnconditionalFlowInfo innerFlowInfos[] = null;
34
	private int innerFlowContextsNb = 0;
34
	private int innerFlowContextsNb = 0;
35
	private LabelFlowContext breakTargetContexts[] = null;
36
	public int breakTargetsNb = 0;
35
	
37
	
36
	Reference finalAssignments[];
38
	Reference finalAssignments[];
37
	VariableBinding finalVariables[];
39
	VariableBinding finalVariables[];
Lines 101-109 Link Here
101
/**
103
/**
102
 * Perform deferred checks relative to the null status of local variables.
104
 * Perform deferred checks relative to the null status of local variables.
103
 * @param scope the scope to which this context is associated
105
 * @param scope the scope to which this context is associated
104
 * @param flowInfo the flow info against which checks must be performed
106
 * @param callerFlowInfo the flow info against which checks must be performed
105
 */
107
 */
106
public void complainOnDeferredNullChecks(BlockScope scope, FlowInfo flowInfo) {
108
public void complainOnDeferredNullChecks(BlockScope scope, FlowInfo callerFlowInfo) {
107
	for (int i = 0 ; i < this.innerFlowContextsNb ; i++) {
109
	for (int i = 0 ; i < this.innerFlowContextsNb ; i++) {
108
		this.upstreamNullFlowInfo.
110
		this.upstreamNullFlowInfo.
109
			addPotentialNullInfoFrom(
111
			addPotentialNullInfoFrom(
Lines 111-119 Link Here
111
			addPotentialNullInfoFrom(this.innerFlowInfos[i]);
113
			addPotentialNullInfoFrom(this.innerFlowInfos[i]);
112
	}
114
	}
113
	this.innerFlowContextsNb = 0;
115
	this.innerFlowContextsNb = 0;
114
	flowInfo = this.upstreamNullFlowInfo.
116
	UnconditionalFlowInfo flowInfo = this.upstreamNullFlowInfo.
115
		addPotentialNullInfoFrom(
117
		addPotentialNullInfoFrom(callerFlowInfo.unconditionalInitsWithoutSideEffect());
116
			flowInfo.unconditionalInitsWithoutSideEffect());
117
	if (this.deferNullDiagnostic) {
118
	if (this.deferNullDiagnostic) {
118
		// check only immutable null checks on innermost looping context
119
		// check only immutable null checks on innermost looping context
119
		for (int i = 0; i < this.nullCount; i++) {
120
		for (int i = 0; i < this.nullCount; i++) {
Lines 247-252 Link Here
247
			}
248
			}
248
		}
249
		}
249
	}
250
	}
251
	// propagate breaks
252
	for (int i = 0; i < this.breakTargetsNb; i++) {
253
		this.breakTargetContexts[i].initsOnBreak.addPotentialNullInfoFrom(flowInfo);
254
	}
250
}
255
}
251
	
256
	
252
	public BranchLabel continueLabel() {
257
	public BranchLabel continueLabel() {
Lines 270-275 Link Here
270
		return initsOnContinue != FlowInfo.DEAD_END;
275
		return initsOnContinue != FlowInfo.DEAD_END;
271
	}
276
	}
272
277
278
public void recordBreakTo(FlowContext targetContext) {
279
	if (targetContext instanceof LabelFlowContext) {
280
		int current;
281
		if ((current = this.breakTargetsNb++) == 0) {
282
			this.breakTargetContexts = new LabelFlowContext[2];
283
		} else if (current == this.breakTargetContexts.length) {
284
			System.arraycopy(this.breakTargetContexts, 0, this.breakTargetContexts = new LabelFlowContext[current + 2], 0, current);
285
		}
286
		this.breakTargetContexts[current] = (LabelFlowContext) targetContext;
287
	}
288
}
289
273
public void recordContinueFrom(FlowContext innerFlowContext, FlowInfo flowInfo) {
290
public void recordContinueFrom(FlowContext innerFlowContext, FlowInfo flowInfo) {
274
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)	{
291
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0)	{
275
	if ((initsOnContinue.tagBits & FlowInfo.UNREACHABLE) == 0) {
292
	if ((initsOnContinue.tagBits & FlowInfo.UNREACHABLE) == 0) {
(-)compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java (+4 lines)
Lines 422-427 Link Here
422
	// default implementation: do nothing
422
	// default implementation: do nothing
423
}
423
}
424
424
425
public void recordBreakTo(FlowContext targetContext) {
426
	// default implementation: do nothing
427
}
428
425
public void recordContinueFrom(FlowContext innerFlowContext, FlowInfo flowInfo) {
429
public void recordContinueFrom(FlowContext innerFlowContext, FlowInfo flowInfo) {
426
	// default implementation: do nothing
430
	// default implementation: do nothing
427
}
431
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java (+1 lines)
Lines 59-64 Link Here
59
			}
59
			}
60
		}
60
		}
61
		traversedContext.recordReturnFrom(flowInfo.unconditionalInits());
61
		traversedContext.recordReturnFrom(flowInfo.unconditionalInits());
62
		traversedContext.recordBreakTo(targetContext);
62
		
63
		
63
		if (traversedContext instanceof InsideSubRoutineFlowContext) {
64
		if (traversedContext instanceof InsideSubRoutineFlowContext) {
64
			ASTNode node = traversedContext.associatedNode;
65
			ASTNode node = traversedContext.associatedNode;
(-)src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java (+18 lines)
Lines 1343-1348 Link Here
1343
		},
1343
		},
1344
		"1");
1344
		"1");
1345
}
1345
}
1346
// do while and named labels
1347
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472
1348
// variant
1349
public void test047() {
1350
	this.runConformTest(
1351
		new String[] {
1352
			"X.java",
1353
			"public class X {\n" + 
1354
			"  public void foo() {\n" + 
1355
			"    done: do\n" + 
1356
			"      break done;\n" + 
1357
			"    while (false);\n" +
1358
			"    System.out.println();\n" + 
1359
			"  }\n" + 
1360
			"}\n",
1361
		},
1362
		"");
1363
}
1346
public static Class testClass() {
1364
public static Class testClass() {
1347
	return FlowAnalysisTest.class;
1365
	return FlowAnalysisTest.class;
1348
}
1366
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (-6 / +178 lines)
Lines 3874-3880 Link Here
3874
// null analysis - while
3874
// null analysis - while
3875
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472
3875
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472
3876
// extraneous error in case of a labeled while(true) statement
3876
// extraneous error in case of a labeled while(true) statement
3877
public void _test0460_while_explicit_label() {
3877
public void test0460_while_explicit_label() {
3878
	this.runConformTest(
3878
	this.runConformTest(
3879
		new String[] {
3879
		new String[] {
3880
			"X.java",
3880
			"X.java",
Lines 3900-3916 Link Here
3900
// null analysis - while
3900
// null analysis - while
3901
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472
3901
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472
3902
// extraneous error in case of a labeled while(true) statement
3902
// extraneous error in case of a labeled while(true) statement
3903
public void _test0461_while_explicit_label() {
3903
public void test0461_while_explicit_label() {
3904
	this.runConformTest(
3904
	this.runConformTest(
3905
		new String[] {
3905
		new String[] {
3906
			"X.java",
3906
			"X.java",
3907
			"public class X {\n" + 
3907
			"public class X {\n" +
3908
			"  void foo(boolean b) {\n" + 
3908
			"  boolean test() {\n" +
3909
			"    return true;\n" +
3910
			"  }\n" + 
3911
			"  void foo() {\n" + 
3909
			"    Object o = null;\n" + 
3912
			"    Object o = null;\n" + 
3910
			"    done: while (true) {\n" + 
3913
			"    done: while (true) {\n" + 
3911
			"      if (b) {\n" + 
3914
			"      if (test()) {\n" + 
3912
			"        break done;\n" + 
3915
			"        break done;\n" + 
3913
			"      }\n" + 
3916
			"      }\n" +
3917
			"      o = new Object();\n" + 
3918
			"    }\n" + 
3919
			"    if (o == null) {\n" + 
3920
			"    }\n" + 
3921
			"  }\n" + 
3922
			"}\n"},
3923
		"");
3924
} 
3925
3926
// null analysis - while
3927
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472
3928
// variant
3929
public void test0462_while_explicit_label() {
3930
	this.runConformTest(
3931
		new String[] {
3932
			"X.java",
3933
			"public class X {\n" +
3934
			"  boolean test() {\n" +
3935
			"    return true;\n" +
3936
			"  }\n" + 
3937
			"  void foo() {\n" + 
3938
			"    Object o = null;\n" + 
3939
			"    done: while (true) {\n" +
3940
			"      try {\n" + 
3941
			"        while (true) {\n" + 
3942
			"          if (test()) {\n" + 
3943
			"            break done;\n" + 
3944
			"          }\n" +
3945
			"        }\n" +
3946
			"      }\n" +
3947
			"      finally {\n" +
3948
			"        if (test()) {\n" + 
3949
			"          o = new Object();\n" + 
3950
			"        }\n" +
3951
			"      }\n" +
3914
			"    }\n" + 
3952
			"    }\n" + 
3915
			"    if (o == null) {\n" + 
3953
			"    if (o == null) {\n" + 
3916
			"    }\n" + 
3954
			"    }\n" + 
Lines 5698-5703 Link Here
5698
	);
5736
	);
5699
}
5737
}
5700
5738
5739
// null analysis - do while
5740
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472
5741
// variant
5742
public void test0616_do_while_explicit_label() {
5743
	this.runConformTest(
5744
		new String[] {
5745
			"X.java",
5746
			"public class X {\n" + 
5747
			"  void foo(int i) {\n" + 
5748
			"    Object o = null;\n" + 
5749
			"    done: do {\n" + 
5750
			"      switch (i) {\n" + 
5751
			"        case 0:\n" + 
5752
			"          o = new Object();\n" + 
5753
			"          break;\n" + 
5754
			"        case 1:\n" + 
5755
			"          break done;\n" + 
5756
			"      }\n" + 
5757
			"    } while (true);\n" + 
5758
			"    if (o == null) {\n" + 
5759
			"    }\n" + 
5760
			"  }\n" + 
5761
			"}\n"},
5762
		"");
5763
} 
5764
5765
// null analysis - do while
5766
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472
5767
// variant
5768
public void test0617_do_while_explicit_label() {
5769
	this.runConformTest(
5770
		new String[] {
5771
			"X.java",
5772
			"public class X {\n" +
5773
			"  boolean test() {\n" +
5774
			"    return true;\n" +
5775
			"  }\n" + 
5776
			"  void foo() {\n" + 
5777
			"    Object o = null;\n" + 
5778
			"    done: do {\n" + 
5779
			"      if (test()) {\n" + 
5780
			"        break done;\n" + 
5781
			"      }\n" +
5782
			"      o = new Object();\n" + 
5783
			"    } while (true);\n" + 
5784
			"    if (o == null) {\n" + 
5785
			"    }\n" + 
5786
			"  }\n" + 
5787
			"}\n"},
5788
		"");
5789
} 
5790
5791
5701
// null analysis -- for
5792
// null analysis -- for
5702
public void test0701_for() {
5793
public void test0701_for() {
5703
	this.runNegativeTest(
5794
	this.runNegativeTest(
Lines 6540-6545 Link Here
6540
	}
6631
	}
6541
}
6632
}
6542
6633
6634
// null analysis - for
6635
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472
6636
// variant
6637
public void test0740_for_explicit_label() {
6638
	this.runConformTest(
6639
		new String[] {
6640
			"X.java",
6641
			"public class X {\n" + 
6642
			"  void foo(int i) {\n" + 
6643
			"    Object o = null;\n" + 
6644
			"    done: for (;;) {\n" + 
6645
			"      switch (i) {\n" + 
6646
			"        case 0:\n" + 
6647
			"          o = new Object();\n" + 
6648
			"          break;\n" + 
6649
			"        case 1:\n" + 
6650
			"          break done;\n" + 
6651
			"      }\n" + 
6652
			"    }\n" + 
6653
			"    if (o == null) {\n" + 
6654
			"    }\n" + 
6655
			"  }\n" + 
6656
			"}\n"},
6657
		"");
6658
} 
6659
6660
// null analysis - for
6661
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472
6662
// variant
6663
public void test0741_for_explicit_label() {
6664
	this.runConformTest(
6665
		new String[] {
6666
			"X.java",
6667
			"public class X {\n" +
6668
			"  boolean test() {\n" +
6669
			"    return true;\n" +
6670
			"  }\n" + 
6671
			"  void foo() {\n" + 
6672
			"    Object o = null;\n" + 
6673
			"    done: for (;;) {\n" + 
6674
			"      if (test()) {\n" + 
6675
			"        break done;\n" + 
6676
			"      }\n" +
6677
			"      o = new Object();\n" + 
6678
			"    }\n" + 
6679
			"    if (o == null) {\n" + 
6680
			"    }\n" + 
6681
			"  }\n" + 
6682
			"}\n"},
6683
		"");
6684
} 
6685
6686
// null analysis - for
6687
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472
6688
// variant
6689
public void test0742_for_explicit_label() {
6690
	if (COMPLIANCE_1_5.compareTo(this.complianceLevel) <= 0) {
6691
		this.runConformTest(
6692
			new String[] {
6693
				"X.java",
6694
				"import java.util.List;\n" + 
6695
				"public class X {\n" + 
6696
				"  void foo(int i, List<Object> l) {\n" + 
6697
				"    Object o = null;\n" + 
6698
				"    done: for (Object j: l) {\n" + 
6699
				"      switch (i) {\n" + 
6700
				"        case 0:\n" + 
6701
				"          o = new Object();\n" + 
6702
				"          break;\n" + 
6703
				"        case 1:\n" + 
6704
				"          break done;\n" + 
6705
				"      }\n" + 
6706
				"    }\n" + 
6707
				"    if (o == null) {\n" + 
6708
				"    }\n" + 
6709
				"  }\n" + 
6710
				"}\n"},
6711
			"");
6712
	}
6713
} 
6714
6543
// null analysis -- switch
6715
// null analysis -- switch
6544
public void test0800_switch() {
6716
public void test0800_switch() {
6545
	this.runConformTest(
6717
	this.runConformTest(

Return to bug 176472