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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/flow/NullInfoRegistry.java (-2 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
2
 * Copyright (c) 2006, 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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - [compiler] [null] Whitebox issues in null analysis,  see https://bugs.eclipse.org/320170   
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.flow;
12
package org.eclipse.jdt.internal.compiler.flow;
12
13
Lines 319-325 Link Here
319
			// prot. non null
320
			// prot. non null
320
		& ((a2 = this.nullBit2) | (a4 = this.nullBit4));
321
		& ((a2 = this.nullBit2) | (a4 = this.nullBit4));
321
			// null or unknown
322
			// null or unknown
322
	m2 = s1 & (s2 = this.nullBit2) & (s3 ^ s4)
323
	m2 = s1 & (s2 = this.nullBit2) & (s3 ^ s4) // TODO(stephan): potential typo: should this be "s2 = source.nullBit2"???
323
			// prot. null
324
			// prot. null
324
		& ((a3 = this.nullBit3) | a4);
325
		& ((a3 = this.nullBit3) | a4);
325
			// non null or unknown
326
			// non null or unknown
Lines 336-341 Link Here
336
		source.nullBit2 &= (nm1 = ~m1) & ((nm2 = ~m2) | a4);
337
		source.nullBit2 &= (nm1 = ~m1) & ((nm2 = ~m2) | a4);
337
		source.nullBit3 &= (nm1 | a2) & nm2;
338
		source.nullBit3 &= (nm1 | a2) & nm2;
338
		source.nullBit4 &= nm1 & nm2;
339
		source.nullBit4 &= nm1 & nm2;
340
		// any variable that is (pot n, pot nn, pot un) at end of try (as captured by *this* NullInfoRegistry)
341
		// has the same uncertainty also for the mitigated case (function result)
342
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=320170 -  [compiler] [null] Whitebox issues in null analysis
343
		// and org.eclipse.jdt.core.tests.compiler.regression.NullReferenceTest.test0536_try_finally()
344
		long x = ~this.nullBit1 & a2 & a3 & a4; // x is set for all variable ids that have state 0111 (pot n, pot nn, pot un)
345
		if (x != 0) {
346
			// restore state 0111 for all variable ids in x:
347
			source.nullBit1 &= ~x;
348
			source.nullBit2 |= x;
349
			source.nullBit3 |= x;
350
			source.nullBit4 |= x;
351
		}
339
	}
352
	}
340
	if (this.extra != null && source.extra != null) {
353
	if (this.extra != null && source.extra != null) {
341
		int length = this.extra[2].length, sourceLength = source.extra[0].length;
354
		int length = this.extra[2].length, sourceLength = source.extra[0].length;
(-)compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java (+2 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - [compiler] [null] Whitebox issues in null analysis,  see https://bugs.eclipse.org/320170   
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.flow;
12
package org.eclipse.jdt.internal.compiler.flow;
12
13
Lines 63-68 Link Here
63
		0100	pot. null
64
		0100	pot. null
64
		0101	pot. n & pot. un
65
		0101	pot. n & pot. un
65
		0110	pot. n & pot. nn
66
		0110	pot. n & pot. nn
67
		0111    pot. n & pot. nn & pot. un
66
		1001	def. unknown
68
		1001	def. unknown
67
		1010	def. non null
69
		1010	def. non null
68
		1011	pot. nn & prot. nn
70
		1011	pot. nn & prot. nn
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceImplTests.java (-2 / +3 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 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - [compiler] [null] Whitebox issues in null analysis,  see https://bugs.eclipse.org/320170   
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
Lines 96-102 Link Here
96
			011001
97
			011001
97
			011010
98
			011010
98
			011011
99
			011011
99
			011100
100
			011100  pot. n & pot. nn & pot. un
100
			011101
101
			011101
101
			011110
102
			011110
102
			011111
103
			011111
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (+73 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - [compiler] [null] Whitebox issues in null analysis,  see https://bugs.eclipse.org/320170   
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
Lines 5484-5489 Link Here
5484
			"");
5485
			"");
5485
}
5486
}
5486
5487
5488
// null analysis -- try/finally
5489
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320170 -  [compiler] [null] Whitebox issues in null analysis
5490
// trigger nullbits 0111 (pot n|nn|un), don't let "definitely unknown" override previous information
5491
public void test0536_try_finally() {
5492
	this.runNegativeTest(
5493
		new String[] {
5494
			"X.java",
5495
			"public class X {\n" +
5496
			" X bar () { return null; }\n" +
5497
			" void foo() {\n" +
5498
			"   X x = new X();\n" +
5499
			"   try {\n" +
5500
			"     x = null;\n" +
5501
			"     x = new X();\n" +  // if this throws an exception finally finds x==null
5502
			"     x = bar();\n" +
5503
			"   } finally {\n" +
5504
			"     x.toString();\n" + // complain
5505
			"   }\n" +
5506
			" }\n" +
5507
			"}\n"},
5508
		"----------\n" + 
5509
		"1. ERROR in X.java (at line 10)\n" + 
5510
		"	x.toString();\n" + 
5511
		"	^\n" + 
5512
		"Potential null pointer access: The variable x may be null at this location\n" + 
5513
		"----------\n",
5514
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
5515
}
5516
5517
// null analysis -- try/finally
5518
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320170 -  [compiler] [null] Whitebox issues in null analysis
5519
// trigger nullbits 0111 (pot n|nn|un), don't let "definitely unknown" override previous information
5520
// multiple variables
5521
public void test0537_try_finally() {
5522
	this.runNegativeTest(
5523
		new String[] {
5524
			"X.java",
5525
			"public class X {\n" +
5526
			" X bar () { return null; }\n" +
5527
			" void foo() {\n" +
5528
			"   X x1 = new X();\n" +
5529
			"   X x2 = new X();\n" +
5530
			"   X x3 = new X();\n" +
5531
			"   try {\n" +
5532
			"     x1 = null;\n" +
5533
			"     x2 = null;\n" +
5534
			"     x1 = new X();\n" +  // if this throws an exception finally finds x1==null
5535
			"     x2 = new X();\n" +  // if this throws an exception finally finds x2==null
5536
			"     x3 = new X();\n" +  // if this throws an exception finally still finds x3!=null
5537
			"     x1 = bar();\n" +
5538
			"     x2 = bar();\n" +
5539
			"   } finally {\n" +
5540
			"     x1.toString();\n" + // complain
5541
			"     x2.toString();\n" + // complain
5542
			"     x3.toString();\n" + // don't complain
5543
			"   }\n" +
5544
			" }\n" +
5545
			"}\n"},
5546
		"----------\n" + 
5547
		"1. ERROR in X.java (at line 16)\n" + 
5548
		"	x1.toString();\n" + 
5549
		"	^^\n" + 
5550
		"Potential null pointer access: The variable x1 may be null at this location\n" + 
5551
		"----------\n" + 
5552
		"2. ERROR in X.java (at line 17)\n" + 
5553
		"	x2.toString();\n" + 
5554
		"	^^\n" + 
5555
		"Potential null pointer access: The variable x2 may be null at this location\n" + 
5556
		"----------\n",
5557
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
5558
}
5559
5487
// null analysis -- try/catch
5560
// null analysis -- try/catch
5488
public void test0550_try_catch() {
5561
public void test0550_try_catch() {
5489
	this.runConformTest(
5562
	this.runConformTest(

Return to bug 320170