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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java (-9 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 229-242 Link Here
229
									scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
229
									scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
230
								}
230
								}
231
								if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
231
								if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
232
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
232
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
233
								}
233
								}
234
							} else if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) {
234
							} else if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) {
235
								if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
235
								if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
236
									scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
236
									scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
237
								}
237
								}
238
								if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
238
								if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
239
									flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
239
									flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
240
								}
240
								}
241
							}
241
							}
242
							return;
242
							return;
Lines 252-258 Link Here
252
										scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
252
										scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
253
									}
253
									}
254
									if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
254
									if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
255
										flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
255
										flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
256
									}
256
									}
257
									return;
257
									return;
258
								case FlowContext.IN_COMPARISON_NON_NULL:
258
								case FlowContext.IN_COMPARISON_NON_NULL:
Lines 264-270 Link Here
264
										scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
264
										scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
265
									}
265
									}
266
									if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
266
									if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
267
										flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
267
										flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
268
									}
268
									}
269
									return;
269
									return;
270
								case FlowContext.IN_ASSIGNMENT:
270
								case FlowContext.IN_ASSIGNMENT:
Lines 314-327 Link Here
314
									scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
314
									scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
315
								}
315
								}
316
								if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
316
								if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
317
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
317
									flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
318
								}
318
								}
319
							} else {
319
							} else {
320
								if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
320
								if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
321
									scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
321
									scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
322
								}
322
								}
323
								if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
323
								if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
324
									flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
324
									flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
325
								}
325
								}
326
							}
326
							}
327
							return;
327
							return;
Lines 342-348 Link Here
342
										scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
342
										scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
343
									}
343
									}
344
									if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
344
									if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
345
										flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
345
										flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
346
									}
346
									}
347
									return;
347
									return;
348
								case FlowContext.IN_COMPARISON_NON_NULL:
348
								case FlowContext.IN_COMPARISON_NON_NULL:
Lines 354-360 Link Here
354
										scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
354
										scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
355
									}
355
									}
356
									if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
356
									if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
357
										flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
357
										flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
358
									}
358
									}
359
									return;
359
									return;
360
								case FlowContext.IN_ASSIGNMENT:
360
								case FlowContext.IN_ASSIGNMENT:
(-)compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java (-5 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 578-591 Link Here
578
						scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
578
						scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
579
					}
579
					}
580
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
580
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
581
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
581
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
582
					}
582
					}
583
				} else {
583
				} else {
584
					if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
584
					if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
585
						scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
585
						scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
586
					}
586
					}
587
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
587
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
588
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
588
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
589
					}
589
					}
590
				}
590
				}
591
				return;
591
				return;
Lines 609-615 Link Here
609
							scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
609
							scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
610
						}
610
						}
611
						if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
611
						if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
612
							flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
612
							flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
613
						}
613
						}
614
						return;
614
						return;
615
					case FlowContext.IN_COMPARISON_NON_NULL:
615
					case FlowContext.IN_COMPARISON_NON_NULL:
Lines 621-627 Link Here
621
							scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
621
							scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
622
						}
622
						}
623
						if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
623
						if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
624
							flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
624
							flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
625
						}
625
						}
626
						return;
626
						return;
627
					case FlowContext.IN_ASSIGNMENT:
627
					case FlowContext.IN_ASSIGNMENT:
(-)compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java (-4 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 22-29 Link Here
22
22
23
	public int tagBits; // REACHABLE by default
23
	public int tagBits; // REACHABLE by default
24
	public final static int REACHABLE = 0;
24
	public final static int REACHABLE = 0;
25
	public final static int UNREACHABLE = 1;
25
	/* unreachable code as defined in the language spec 
26
	 * eg. while (true);
27
	 *     i++;  --> unreachable code 
28
	 */
29
	public final static int UNREACHABLE_OR_DEAD = 1;
26
	public final static int NULL_FLAG_MASK = 2;
30
	public final static int NULL_FLAG_MASK = 2;
31
	/* unreachable code as inferred by null analysis
32
	 * eg. str = null;
33
	 *     if (str != null) {
34
	 *        // dead code
35
	 *     }
36
	 */
37
	public final static int UNREACHABLE_BY_NULLANALYSIS = 4;
38
	/*
39
	 * code unreachable in any fashion
40
	 */
41
	public final static int UNREACHABLE = UNREACHABLE_OR_DEAD | UNREACHABLE_BY_NULLANALYSIS;
27
42
28
	public final static int UNKNOWN = 1;
43
	public final static int UNKNOWN = 1;
29
	public final static int NULL = 2;
44
	public final static int NULL = 2;
Lines 456-464 Link Here
456
}
471
}
457
472
458
/**
473
/**
459
 * Return REACHABLE if this flow info is reachable, UNREACHABLE
474
 * Return REACHABLE if this flow info is reachable, UNREACHABLE|UNREACHABLE_BY_NULLANALYSIS
460
 * else.
475
 * else.
461
 * @return REACHABLE if this flow info is reachable, UNREACHABLE
476
 * @return REACHABLE if this flow info is reachable, UNREACHABLE|UNREACHABLE_BY_NULLANALYSIS
462
 *         else
477
 *         else
463
 */
478
 */
464
public int reachMode() {
479
public int reachMode() {
(-)compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java (-6 / +6 lines)
Lines 493-506 Link Here
493
						scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
493
						scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference);
494
					}
494
					}
495
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
495
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
496
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
496
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
497
					}
497
					}
498
				} else {
498
				} else {
499
					if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
499
					if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
500
						scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
500
						scope.problemReporter().localVariableNonNullComparedToNull(local, reference);
501
					}
501
					}
502
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
502
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
503
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
503
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
504
					}
504
					}
505
				}
505
				}
506
			} else if (flowInfo.isDefinitelyNull(local)) {
506
			} else if (flowInfo.isDefinitelyNull(local)) {
Lines 509-522 Link Here
509
						scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
509
						scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
510
					}
510
					}
511
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
511
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
512
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
512
						flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
513
					}
513
					}
514
				} else {
514
				} else {
515
					if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
515
					if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) {
516
						scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
516
						scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
517
					}
517
					}
518
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
518
					if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
519
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
519
						flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
520
					}
520
					}
521
				}
521
				}
522
			} else if (this.upstreamNullFlowInfo.isDefinitelyNonNull(local) && !flowInfo.isPotentiallyNull(local) && !flowInfo.isPotentiallyUnknown(local)) {    
522
			} else if (this.upstreamNullFlowInfo.isDefinitelyNonNull(local) && !flowInfo.isPotentiallyNull(local) && !flowInfo.isPotentiallyUnknown(local)) {    
Lines 554-560 Link Here
554
							scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
554
							scope.problemReporter().localVariableRedundantCheckOnNull(local, reference);
555
						}
555
						}
556
						if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
556
						if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
557
							flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE);
557
							flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
558
						}
558
						}
559
						return;
559
						return;
560
					case FlowContext.IN_COMPARISON_NON_NULL:
560
					case FlowContext.IN_COMPARISON_NON_NULL:
Lines 566-572 Link Here
566
							scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
566
							scope.problemReporter().localVariableNullComparedToNonNull(local, reference);
567
						}
567
						}
568
						if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
568
						if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) {
569
							flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE);
569
							flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS);
570
						}
570
						}
571
						return;
571
						return;
572
					case FlowContext.IN_ASSIGNMENT:
572
					case FlowContext.IN_ASSIGNMENT:
(-)compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java (-2 / +16 lines)
Lines 731-737 Link Here
731
final public boolean isDefinitelyAssigned(FieldBinding field) {
731
final public boolean isDefinitelyAssigned(FieldBinding field) {
732
	// Mirrored in CodeStream.isDefinitelyAssigned(..)
732
	// Mirrored in CodeStream.isDefinitelyAssigned(..)
733
	// do not want to complain in unreachable code
733
	// do not want to complain in unreachable code
734
	if ((this.tagBits & UNREACHABLE) != 0) {
734
	if ((this.tagBits & UNREACHABLE_OR_DEAD) != 0) {
735
		return true;
735
		return true;
736
	}
736
	}
737
	return isDefinitelyAssigned(field.id);
737
	return isDefinitelyAssigned(field.id);
Lines 739-745 Link Here
739
739
740
final public boolean isDefinitelyAssigned(LocalVariableBinding local) {
740
final public boolean isDefinitelyAssigned(LocalVariableBinding local) {
741
	// do not want to complain in unreachable code if local declared in reachable code
741
	// do not want to complain in unreachable code if local declared in reachable code
742
	if ((this.tagBits & UNREACHABLE) != 0 && (local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0) {
742
	if ((this.tagBits & UNREACHABLE_OR_DEAD) != 0 && (local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0) {
743
		return true;
743
		return true;
744
	}
744
	}
745
	return isDefinitelyAssigned(local.id + this.maxFieldCount);
745
	return isDefinitelyAssigned(local.id + this.maxFieldCount);
Lines 1563-1568 Link Here
1563
		na1, na2, na3, na4,
1563
		na1, na2, na3, na4,
1564
		nb1, nb2, nb3, nb4,
1564
		nb1, nb2, nb3, nb4,
1565
		b1, b2, b3, b4;
1565
		b1, b2, b3, b4;
1566
  if ((otherInits.tagBits & FlowInfo.UNREACHABLE_BY_NULLANALYSIS) != 0) {
1567
	  otherHasNulls = false; // skip merging, otherInits is unreachable by null analysis
1568
  } else {
1569
	if ((this.tagBits & FlowInfo.UNREACHABLE_BY_NULLANALYSIS) != 0) { // directly copy if this is unreachable by null analysis
1570
		this.nullBit1 = otherInits.nullBit1;
1571
		this.nullBit2 = otherInits.nullBit2;
1572
		this.nullBit3 = otherInits.nullBit3;
1573
		this.nullBit4 = otherInits.nullBit4;
1574
		thisHadNulls = false;
1575
		thisHasNulls = otherHasNulls;
1576
	} else
1566
	if (thisHadNulls) {
1577
	if (thisHadNulls) {
1567
    	if (otherHasNulls) {
1578
    	if (otherHasNulls) {
1568
    		this.nullBit1 = (a2 = this.nullBit2) & (a3 = this.nullBit3)
1579
    		this.nullBit1 = (a2 = this.nullBit2) & (a3 = this.nullBit3)
Lines 1636-1641 Link Here
1636
    		this.nullBit3 != 0 ||
1647
    		this.nullBit3 != 0 ||
1637
    		this.nullBit4 != 0;
1648
    		this.nullBit4 != 0;
1638
	}
1649
	}
1650
  }
1639
1651
1640
	// treating extra storage
1652
	// treating extra storage
1641
	if (this.extra != null || otherInits.extra != null) {
1653
	if (this.extra != null || otherInits.extra != null) {
Lines 1858-1863 Link Here
1858
	}	
1870
	}	
1859
	if (reachMode == REACHABLE ) {
1871
	if (reachMode == REACHABLE ) {
1860
		this.tagBits &= ~UNREACHABLE;
1872
		this.tagBits &= ~UNREACHABLE;
1873
	} else if (reachMode == UNREACHABLE_BY_NULLANALYSIS) {
1874
		this.tagBits |= UNREACHABLE_BY_NULLANALYSIS; // don't interfere with definite assignment analysis
1861
	} else {
1875
	} else {
1862
		if ((this.tagBits & UNREACHABLE) == 0) {
1876
		if ((this.tagBits & UNREACHABLE) == 0) {
1863
			// reset optional inits when becoming unreachable
1877
			// reset optional inits when becoming unreachable
(-)src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java (-1 / +89 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2010 IBM Corporation and others.
2
 * Copyright (c) 2005, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 29-35 Link Here
29
public class FlowAnalysisTest extends AbstractRegressionTest {
29
public class FlowAnalysisTest extends AbstractRegressionTest {
30
static {
30
static {
31
//	TESTS_NUMBERS = new int[] { 69 };
31
//	TESTS_NUMBERS = new int[] { 69 };
32
//	TESTS_NAMES = new String[] { "testBug338234" };
32
}
33
}
34
33
public FlowAnalysisTest(String name) {
35
public FlowAnalysisTest(String name) {
34
	super(name);
36
	super(name);
35
}
37
}
Lines 2246-2251 Link Here
2246
		"Dead code\n" + 
2248
		"Dead code\n" + 
2247
		"----------\n");
2249
		"----------\n");
2248
}
2250
}
2251
2252
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338234
2253
// Warn uninitialized variable in deadcode if deadcode has been inferred
2254
// by null analysis
2255
public void testBug338234a() {
2256
	this.runNegativeTest(
2257
		new String[] {
2258
			"X.java",
2259
			"public class X {\n" +
2260
			"    public static void main(String[] args) {\n" + 
2261
			"        int i;\n" + 
2262
			"        String str = null;\n" + 
2263
			"        if (str != null)\n" + 
2264
			"            i++;    \n" + 
2265
			"    }\n" + 
2266
			"}\n"
2267
		},
2268
		"----------\n" + 
2269
		"1. WARNING in X.java (at line 6)\n" + 
2270
		"	i++;    \n" + 
2271
		"	^^^\n" + 
2272
		"Dead code\n" + 
2273
		"----------\n" + 
2274
		"2. ERROR in X.java (at line 6)\n" + 
2275
		"	i++;    \n" + 
2276
		"	^\n" + 
2277
		"The local variable i may not have been initialized\n" + 
2278
		"----------\n");
2279
}
2280
2281
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338234
2282
// Don't warn uninitialized variable in deadcode if deadcode has not been inferred
2283
// by null analysis
2284
public void testBug338234b() {
2285
	this.runConformTest(
2286
		new String[] {
2287
			"X.java",
2288
			"public class X {\n" +
2289
			"    public static void main(String[] args) {\n" + 
2290
			"        int i;\n" + 
2291
			"        l: {\n" +
2292
			"			if(false)\n" +
2293
			"				break l;\n" + 
2294
			"        	return;\n" +
2295
			"		 }\n" + 
2296
			"        i++;    \n" + 
2297
			"    }\n" + 
2298
			"}\n"
2299
		},
2300
		"");
2301
}
2302
2303
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338234
2304
// Warn uninitialized field in deadcode if deadcode has been inferred
2305
// by null analysis
2306
public void testBug338234c() {
2307
	this.runNegativeTest(
2308
		new String[] {
2309
			"X.java",
2310
			"public class X {\n" +
2311
			"    public final int field1;\n" +
2312
			"    {\n" + 
2313
			"        int i;\n" + 
2314
			"        String str = null;\n" +
2315
			"		 if(str != null)\n" +
2316
			"			i = field1;\n" + 
2317
			"    }\n" + 
2318
			"}\n"
2319
		},
2320
		"----------\n" + 
2321
		"1. ERROR in X.java (at line 1)\n" + 
2322
		"	public class X {\n" + 
2323
		"	             ^\n" + 
2324
		"The blank final field field1 may not have been initialized\n" + 
2325
		"----------\n" + 
2326
		"2. WARNING in X.java (at line 7)\n" + 
2327
		"	i = field1;\n" + 
2328
		"	^^^^^^^^^^\n" + 
2329
		"Dead code\n" + 
2330
		"----------\n" + 
2331
		"3. ERROR in X.java (at line 7)\n" + 
2332
		"	i = field1;\n" + 
2333
		"	    ^^^^^^\n" + 
2334
		"The blank final field field1 may not have been initialized\n" + 
2335
		"----------\n");
2336
}
2249
public static Class testClass() {
2337
public static Class testClass() {
2250
	return FlowAnalysisTest.class;
2338
	return FlowAnalysisTest.class;
2251
}
2339
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (+24 lines)
Lines 14060-14063 Link Here
14060
		},
14060
		},
14061
		"");
14061
		"");
14062
}
14062
}
14063
14064
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338234
14065
public void testBug338234() {
14066
	this.runNegativeTest(
14067
		new String[] {
14068
			"X.java",
14069
			"public class X {\n" + 
14070
			"   static int foo() {\n" + 
14071
			"        Object o = null;\n" +
14072
			"		 int i = 0;\n" + 
14073
			"        label: {\n" + 
14074
			"            if (o == null)\n" + 
14075
			"                break label;\n" +
14076
			"			 i++;" + 
14077
			"        }\n" + 
14078
			"         if (i != 0) {\n" + 
14079
			"            System.out.println(i);\n" + 
14080
			"        }\n" + 
14081
			"        return 0;\n" + 
14082
			"    }\n" + 
14083
			"}\n"
14084
		},
14085
		"");
14086
}
14063
}
14087
}

Return to bug 338234