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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java (-6 / +6 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 565-571 Link Here
565
 */
565
 */
566
public void recordUsingNullReference(Scope scope, LocalVariableBinding local,
566
public void recordUsingNullReference(Scope scope, LocalVariableBinding local,
567
		Expression reference, int checkType, FlowInfo flowInfo) {
567
		Expression reference, int checkType, FlowInfo flowInfo) {
568
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) != 0 ||
568
	if ((flowInfo.tagBits & (FlowInfo.UNREACHABLE|FlowInfo.UNREACHABLE_BY_NULLANALYSIS)) != 0 ||
569
			flowInfo.isDefinitelyUnknown(local)) {
569
			flowInfo.isDefinitelyUnknown(local)) {
570
		return;
570
		return;
571
	}
571
	}
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 (-1 / +3 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 24-29 Link Here
24
	public final static int REACHABLE = 0;
24
	public final static int REACHABLE = 0;
25
	public final static int UNREACHABLE = 1;
25
	public final static int UNREACHABLE = 1;
26
	public final static int NULL_FLAG_MASK = 2;
26
	public final static int NULL_FLAG_MASK = 2;
27
	public static final int UNREACHABLE_BY_NULLANALYSIS = 4;
28
	
27
29
28
	public final static int UNKNOWN = 1;
30
	public final static int UNKNOWN = 1;
29
	public final static int NULL = 2;
31
	public final static int NULL = 2;
(-)compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java (+14 lines)
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 / +24 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
public void testBug338234() {
2253
	runNegativeTest(
2254
		new String[] {
2255
			"X.java",
2256
			"public class X {\n" +
2257
			"    public static void main(String[] args) {\n" + 
2258
			"        int i;\n" + 
2259
			"        String str = null;\n" + 
2260
			"        if (str != null)\n" + 
2261
			"            i++;    \n" + 
2262
			"    }\n" + 
2263
			"}\n"
2264
		},
2265
		"----------\n" + 
2266
		"1. ERROR in X.java (at line 6)\n" + 
2267
		"	i++;    \n" + 
2268
		"	^\n" + 
2269
		"The local variable i may not have been initialized\n" + 
2270
		"----------\n");
2271
}
2249
public static Class testClass() {
2272
public static Class testClass() {
2250
	return FlowAnalysisTest.class;
2273
	return FlowAnalysisTest.class;
2251
}
2274
}

Return to bug 338234