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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java (+23 lines)
Lines 1520-1525 Link Here
1520
                        			| na2 & (nb3 | nb2))
1520
                        			| na2 & (nb3 | nb2))
1521
                			| na2 & b3 & b4
1521
                			| na2 & b3 & b4
1522
                			| a2 & (nb1 & b4 | a3 & na4 & b1) & nb3);
1522
                			| a2 & (nb1 & b4 | a3 & na4 & b1) & nb3);
1523
    		// the above formulae do not handle the state 0111, do it now explicitly:
1524
    		long ax = ~a1 & a2 & a3 & a4;
1525
    		long bx = ~b1 & b2 & b3 & b4;
1526
    		long x = ax|bx;
1527
    		if (x != 0) {
1528
    			// restore state 0111 for all variable ids in x:
1529
    			this.nullBit1 &= ~x;
1530
    			this.nullBit2 |= x;
1531
    			this.nullBit3 |= x;
1532
    			this.nullBit4 |= x;
1533
    		}
1534
		
1523
    		if (COVERAGE_TEST_FLAG) {
1535
    		if (COVERAGE_TEST_FLAG) {
1524
    			if(CoverageTestId == 30) {
1536
    			if(CoverageTestId == 30) {
1525
	    		  	this.nullBit4 = ~0;
1537
	    		  	this.nullBit4 = ~0;
Lines 1664-1669 Link Here
1664
                        			| na2 & (nb3 | nb2))
1676
                        			| na2 & (nb3 | nb2))
1665
                			| na2 & b3 & b4
1677
                			| na2 & b3 & b4
1666
                			| a2 & (nb1 & b4 | a3 & na4 & b1) & nb3);
1678
                			| a2 & (nb1 & b4 | a3 & na4 & b1) & nb3);
1679
    		// the above formulae do not handle the state 0111, do it now explicitly:
1680
    		long ax = ~a1 & a2 & a3 & a4;
1681
    		long bx = ~b1 & b2 & b3 & b4;
1682
    		long x = ax|bx;
1683
    		if (x != 0) {
1684
    			// restore state 0111 for all variable ids in x:
1685
    			this.extra[2][i] &= ~x;
1686
    			this.extra[3][i] |= x;
1687
    			this.extra[4][i] |= x;
1688
    			this.extra[5][i] |= x;
1689
    		}
1667
			thisHasNulls = thisHasNulls ||
1690
			thisHasNulls = thisHasNulls ||
1668
				this.extra[3][i] != 0 ||
1691
				this.extra[3][i] != 0 ||
1669
				this.extra[4][i] != 0 ||
1692
				this.extra[4][i] != 0 ||
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (+69 lines)
Lines 13493-13496 Link Here
13493
			null);
13493
			null);
13494
	}
13494
	}
13495
}
13495
}
13496
13497
//null analysis -- conditional expression
13498
public void testBug325755() {
13499
	this.runConformTest(
13500
		new String[] {
13501
			"X.java",
13502
			"public class X {\n" + 
13503
			"	public static Object foo(String s1, String s2) {\n" + 
13504
			"		String local1 = s1;\n" + 
13505
			"		String local2 = s2;\n" + 
13506
			"		\n" + 
13507
			"		String local3 = null;\n" + 
13508
			"		if (local1 != null && local2 != null)\n" + 
13509
			"			local3 = \"\"; //$NON-NLS-1$\n" + 
13510
			"		else\n" + 
13511
			"			local3 = local1 != null ? local1 : local2;\n" + 
13512
			"\n" + 
13513
			"		if (local3 != null)\n" + 
13514
			"			return new Integer(local3.length());\n" + 
13515
			"		return null;\n" + 
13516
			"	}\n" + 
13517
			"	\n" + 
13518
			"	public static void main(String[] args) {\n" + 
13519
			"		System.out.print(foo(null, null));\n" + 
13520
			"		System.out.print(foo(\"p1\", null));\n" + 
13521
			"		System.out.print(foo(null, \"p2\"));\n" + 
13522
			"		System.out.print(foo(\"p1\", \"p2\"));\n" + 
13523
			"	}\n" + 
13524
			"}"},
13525
		"null220");
13526
}
13527
//null analysis -- conditional expression, many locals
13528
public void testBug325755b() {
13529
	this.runConformTest(
13530
		new String[] {
13531
			"X.java",
13532
			"public class X {\n" + 
13533
			"	public static Object foo(String s1, String s2) {\n" + 
13534
	          "    int i00, i01, i02, i03, i04, i05, i06, i07, i08, i09;\n" +
13535
	          "    int i10, i11, i12, i13, i14, i15, i16, i17, i18, i19;\n" +
13536
	          "    int i20, i21, i22, i23, i24, i25, i26, i27, i28, i29;\n" +
13537
	          "    int i30, i31, i32, i33, i34, i35, i36, i37, i38, i39;\n" +
13538
	          "    int i40, i41, i42, i43, i44, i45, i46, i47, i48, i49;\n" +
13539
	          "    int i50, i51, i52, i53, i54, i55, i56, i57, i58, i59;\n" +
13540
	          "    int i60, i61, i62, i63, i64, i65, i66, i67, i68, i69;\n" +
13541
13542
			"		String local1 = s1;\n" + 
13543
			"		String local2 = s2;\n" + 
13544
			"		\n" + 
13545
			"		String local3 = null;\n" + 
13546
			"		if (local1 != null && local2 != null)\n" + 
13547
			"			local3 = \"\"; //$NON-NLS-1$\n" + 
13548
			"		else\n" + 
13549
			"			local3 = local1 != null ? local1 : local2;\n" + 
13550
			"\n" + 
13551
			"		if (local3 != null)\n" + 
13552
			"			return new Integer(local3.length());\n" + 
13553
			"		return null;\n" + 
13554
			"	}\n" + 
13555
			"	\n" + 
13556
			"	public static void main(String[] args) {\n" + 
13557
			"		System.out.print(foo(null, null));\n" + 
13558
			"		System.out.print(foo(\"p1\", null));\n" + 
13559
			"		System.out.print(foo(null, \"p2\"));\n" + 
13560
			"		System.out.print(foo(\"p1\", \"p2\"));\n" + 
13561
			"	}\n" + 
13562
			"}"},
13563
		"null220");
13564
}
13496
}
13565
}

Return to bug 325755