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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (+37 lines)
Lines 5583-5588 Link Here
5583
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
5583
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
5584
}
5584
}
5585
5585
5586
// null analysis -- try/catch,
5587
// combines https://bugs.eclipse.org/bugs/show_bug.cgi?id=320170 -  [compiler] [null] Whitebox issues in null analysis
5588
// and      https://bugs.eclipse.org/bugs/show_bug.cgi?id=325755 -  [compiler] wrong initialization state after conditional expression
5589
public void test0536_try_catch() {
5590
	this.runNegativeTest(
5591
		new String[] {
5592
			"X.java",
5593
			"public class X {\n" +
5594
			" X() { throw new RuntimeException(); }\n" +
5595
			" X bar () { return null; }\n" +
5596
			" void foo(boolean b) {\n" +
5597
			"   X x = new X();\n" +
5598
			"   try {\n" +
5599
			"     x = null;\n" +
5600
			"     x = new X();\n" +  // if this throws an exception catch finds x==null
5601
			"     x = bar();\n" +
5602
			"   } catch (Throwable t) {\n" +
5603
			"     X y;" +
5604
			"     if (b)\n" +
5605
			"       y= new X();\n" +
5606
			"     else\n" +
5607
			"       y = x;\n" +
5608
			"     if (y!=null)\n" +  		// don't complain as redundant
5609
			"       System.out.print(\"nonnull\");\n" +
5610
			"     System.out.print(x.toString());\n" + // complain: x can be null
5611
			"   }\n" +
5612
			" }\n" +
5613
			"}\n"},
5614
		"----------\n" + 
5615
		"1. ERROR in X.java (at line 17)\n" + 
5616
		"	System.out.print(x.toString());\n" + 
5617
		"	                 ^\n" + 
5618
		"Potential null pointer access: The variable x may be null at this location\n" + 
5619
		"----------\n",
5620
	    JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
5621
}
5622
5586
// null analysis -- try/finally
5623
// null analysis -- try/finally
5587
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320170 -  [compiler] [null] Whitebox issues in null analysis
5624
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320170 -  [compiler] [null] Whitebox issues in null analysis
5588
// trigger nullbits 0111 (pot n|nn|un), don't let "definitely unknown" override previous information
5625
// trigger nullbits 0111 (pot n|nn|un), don't let "definitely unknown" override previous information

Return to bug 325755