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 (-1 / +13 lines)
Lines 319-325 Link Here
319
			// prot. non null
319
			// prot. non null
320
		& ((a2 = this.nullBit2) | (a4 = this.nullBit4));
320
		& ((a2 = this.nullBit2) | (a4 = this.nullBit4));
321
			// null or unknown
321
			// null or unknown
322
	m2 = s1 & (s2 = this.nullBit2) & (s3 ^ s4)
322
	m2 = s1 & (s2 = this.nullBit2) & (s3 ^ s4) // TODO(stephan): potential typo: should this be "s2 = source.nullBit2"???
323
			// prot. null
323
			// prot. null
324
		& ((a3 = this.nullBit3) | a4);
324
		& ((a3 = this.nullBit3) | a4);
325
			// non null or unknown
325
			// non null or unknown
Lines 336-341 Link Here
336
		source.nullBit2 &= (nm1 = ~m1) & ((nm2 = ~m2) | a4);
336
		source.nullBit2 &= (nm1 = ~m1) & ((nm2 = ~m2) | a4);
337
		source.nullBit3 &= (nm1 | a2) & nm2;
337
		source.nullBit3 &= (nm1 | a2) & nm2;
338
		source.nullBit4 &= nm1 & nm2;
338
		source.nullBit4 &= nm1 & nm2;
339
		// any variable that is (pot n, pot nn, pot un) at end of try (as captured by *this* NullInfoRegistry)
340
		// has the same uncertainty also for the mitigated case (function result)
341
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=320170 -  [compiler] [null] Whitebox issues in null analysis
342
		// and org.eclipse.jdt.core.tests.compiler.regression.NullReferenceTest.test0536_try_finally()
343
		long x = ~this.nullBit1 & a2 & a3 & a4; // x is set for all variable ids that have state 0111 (pot n, pot nn, pot un)
344
		if (x != 0) {
345
			// restore state 0111 for all variable ids in x:
346
			source.nullBit1 &= ~x;
347
			source.nullBit2 |= x;
348
			source.nullBit3 |= x;
349
			source.nullBit4 |= x;
350
		}
339
	}
351
	}
340
	if (this.extra != null && source.extra != null) {
352
	if (this.extra != null && source.extra != null) {
341
		int length = this.extra[2].length, sourceLength = source.extra[0].length;
353
		int length = this.extra[2].length, sourceLength = source.extra[0].length;
(-)compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java (+1 lines)
Lines 63-68 Link Here
63
		0100	pot. null
63
		0100	pot. null
64
		0101	pot. n & pot. un
64
		0101	pot. n & pot. un
65
		0110	pot. n & pot. nn
65
		0110	pot. n & pot. nn
66
		0111    pot. n & pot. nn & pot. un
66
		1001	def. unknown
67
		1001	def. unknown
67
		1010	def. non null
68
		1010	def. non null
68
		1011	pot. nn & prot. nn
69
		1011	pot. nn & prot. nn
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceImplTests.java (-1 / +1 lines)
Lines 96-102 Link Here
96
			011001
96
			011001
97
			011010
97
			011010
98
			011011
98
			011011
99
			011100
99
			011100  pot. n & pot. nn & pot. un
100
			011101
100
			011101
101
			011110
101
			011110
102
			011111
102
			011111
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (+29 lines)
Lines 5484-5489 Link Here
5484
			"");
5484
			"");
5485
}
5485
}
5486
5486
5487
// null analysis -- try/finally
5488
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320170 -  [compiler] [null] Whitebox issues in null analysis
5489
// trigger nullbits 0111 (pot n|nn|un), don't let "definitely unknown" override previous information
5490
public void test0536_try_finally() {
5491
	this.runNegativeTest(
5492
		new String[] {
5493
			"X.java",
5494
			"public class X {\n" +
5495
			" X bar () { return null; }\n" +
5496
			" void foo() {\n" +
5497
			"   X x = new X();\n" +
5498
			"   try {\n" +
5499
			"     x = null;\n" +
5500
			"     x = new X();\n" +  // if this throws an exception finally finds x==null
5501
			"     x = bar();\n" +
5502
			"   } finally {\n" +
5503
			"     x.toString();\n" + // complain
5504
			"   }\n" +
5505
			" }\n" +
5506
			"}\n"},
5507
		"----------\n" + 
5508
		"1. ERROR in X.java (at line 10)\n" + 
5509
		"	x.toString();\n" + 
5510
		"	^\n" + 
5511
		"Potential null pointer access: The variable x may be null at this location\n" + 
5512
		"----------\n",
5513
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
5514
}
5515
5487
// null analysis -- try/catch
5516
// null analysis -- try/catch
5488
public void test0550_try_catch() {
5517
public void test0550_try_catch() {
5489
	this.runConformTest(
5518
	this.runConformTest(

Return to bug 320170