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

(-)compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java (-2 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 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 62-70 Link Here
62
			}
62
			}
63
		}
63
		}
64
		rightInfo = this.right.analyseCode(currentScope, flowContext, rightInfo);
64
		rightInfo = this.right.analyseCode(currentScope, flowContext, rightInfo);
65
		// The definitely null variables in right info when true should not be missed out while merging
66
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=299900
67
		FlowInfo leftInfoWhenTrueForMerging = leftInfo.initsWhenTrue().unconditionalCopy().addPotentialInitializationsFrom(rightInfo.unconditionalInitsWithoutSideEffect());
65
		FlowInfo mergedInfo = FlowInfo.conditional(
68
		FlowInfo mergedInfo = FlowInfo.conditional(
66
					// merging two true initInfos for such a negative case: if ((t && (b = t)) || f) r = b; // b may not have been initialized
69
					// merging two true initInfos for such a negative case: if ((t && (b = t)) || f) r = b; // b may not have been initialized
67
					leftInfo.initsWhenTrue().unconditionalInits().mergedWith(
70
				leftInfoWhenTrueForMerging.unconditionalInits().mergedWith(
68
						rightInfo.safeInitsWhenTrue().setReachMode(previousMode).unconditionalInits()),
71
						rightInfo.safeInitsWhenTrue().setReachMode(previousMode).unconditionalInits()),
69
					rightInfo.initsWhenFalse());
72
					rightInfo.initsWhenFalse());
70
		this.mergedInitStateIndex =
73
		this.mergedInitStateIndex =
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (-1 / +57 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
2
 * Copyright (c) 2005, 2010 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 10328-10331 Link Here
10328
				"----------\n");
10328
				"----------\n");
10329
	}
10329
	}
10330
}
10330
}
10331
10332
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=299900
10333
// Test to verify that null checks are properly reported for the variable(s)	 
10334
// in the right expression of an OR condition statement.
10335
public void testBug299900a() {
10336
	this.runNegativeTest(
10337
		new String[] {
10338
			"X.java",
10339
			"class X {\n" +
10340
			"  void foo(Object foo, Object bar) {\n" +
10341
			"    if(foo == null || bar == null) {\n" +
10342
			"	 	System.out.println(foo.toString());\n" +
10343
			"	 	System.out.println(bar.toString());\n" +
10344
			"    }\n" +
10345
			"  }\n" +
10346
			"}"},
10347
		"----------\n" +
10348
		"1. ERROR in X.java (at line 4)\n" +
10349
		"	System.out.println(foo.toString());\n" +
10350
		"	                   ^^^\n" +
10351
		"Potential null pointer access: The variable foo may be null at this location\n" +
10352
		"----------\n" +
10353
		"2. ERROR in X.java (at line 5)\n" +
10354
		"	System.out.println(bar.toString());\n" +
10355
		"	                   ^^^\n" +
10356
		"Potential null pointer access: The variable bar may be null at this location\n" + 
10357
		"----------\n");
10358
}
10359
10360
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=299900
10361
// Test to verify that null checks are properly reported for the variable(s)	 
10362
// in the right expression of an OR condition statement.
10363
public void testBug299900b() {
10364
	this.runNegativeTest(
10365
		new String[] {
10366
			"X.java",
10367
			"class X {\n" +
10368
			"  void foo(Object foo, Object bar) {\n" +
10369
			"    if(foo == null || bar == null) {\n" +
10370
			"    }\n" +
10371
			"	 System.out.println(foo.toString());\n" +
10372
			"	 System.out.println(bar.toString());\n" +
10373
			"  }\n" +
10374
			"}"},
10375
		"----------\n" + 
10376
		"1. ERROR in X.java (at line 5)\n" +
10377
		"	System.out.println(foo.toString());\n" +
10378
		"	                   ^^^\n" +
10379
		"Potential null pointer access: The variable foo may be null at this location\n" +
10380
		"----------\n" +
10381
		"2. ERROR in X.java (at line 6)\n" +
10382
		"	System.out.println(bar.toString());\n" +
10383
		"	                   ^^^\n" +
10384
		"Potential null pointer access: The variable bar may be null at this location\n" + 
10385
		"----------\n");
10386
}
10331
}
10387
}

Return to bug 299900