Lines 11662-11665
Link Here
|
11662 |
"----------\n", |
11662 |
"----------\n", |
11663 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11663 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11664 |
} |
11664 |
} |
|
|
11665 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 |
11666 |
// unboxing raises an NPE |
11667 |
public void testBug319201() { |
11668 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
11669 |
return; |
11670 |
runNegativeTest( |
11671 |
new String[] { |
11672 |
"X.java", |
11673 |
"public class X {\n" + |
11674 |
" public void foo() {\n" + |
11675 |
" Integer i = null;\n" + |
11676 |
" int j = i;\n" + // should warn |
11677 |
" }\n" + |
11678 |
"}"}, |
11679 |
"----------\n" + |
11680 |
"1. ERROR in X.java (at line 4)\n" + |
11681 |
" int j = i;\n" + |
11682 |
" ^\n" + |
11683 |
"Null pointer access: The variable i can only be null at this location\n" + |
11684 |
"----------\n", |
11685 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11686 |
} |
11687 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 |
11688 |
//unboxing could raise an NPE |
11689 |
public void testBug319201a() { |
11690 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
11691 |
return; |
11692 |
runNegativeTest( |
11693 |
new String[] { |
11694 |
"X.java", |
11695 |
"public class X {\n" + |
11696 |
" public void foo(Integer i) {\n" + |
11697 |
" if (i == null) {};\n" + |
11698 |
" int j;\n" + |
11699 |
" j = i;\n" + // should warn |
11700 |
" }\n" + |
11701 |
"}"}, |
11702 |
"----------\n" + |
11703 |
"1. ERROR in X.java (at line 5)\n" + |
11704 |
" j = i;\n" + |
11705 |
" ^\n" + |
11706 |
"Potential null pointer access: The variable i may be null at this location\n" + |
11707 |
"----------\n", |
11708 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11709 |
} |
11710 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 |
11711 |
//unboxing raises an NPE |
11712 |
public void testBug319201b() { |
11713 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
11714 |
return; |
11715 |
runNegativeTest( |
11716 |
new String[] { |
11717 |
"X.java", |
11718 |
"public class X {\n" + |
11719 |
" public void foo() {\n" + |
11720 |
" Boolean bo = null;;\n" + |
11721 |
" bar(bo);\n" + // should warn |
11722 |
" }\n" + |
11723 |
" void bar(boolean b) {}\n" + |
11724 |
"}"}, |
11725 |
"----------\n" + |
11726 |
"1. ERROR in X.java (at line 4)\n" + |
11727 |
" bar(bo);\n" + |
11728 |
" ^^\n" + |
11729 |
"Null pointer access: The variable bo can only be null at this location\n" + |
11730 |
"----------\n", |
11731 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11732 |
} |
11733 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 |
11734 |
//unboxing raises an NPE |
11735 |
public void testBug319201c() { |
11736 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
11737 |
return; |
11738 |
runNegativeTest( |
11739 |
new String[] { |
11740 |
"X.java", |
11741 |
"class Y { public Y(boolean b1, boolean b2) {} }\n" + |
11742 |
"public class X extends Y {\n" + |
11743 |
" public X(boolean b, Boolean b2) {\n" + |
11744 |
" super(b2 == null, b2);\n" + |
11745 |
" }\n" + |
11746 |
" class Z {\n" + |
11747 |
" public Z(boolean b) {}\n" + |
11748 |
" }\n" + |
11749 |
" boolean fB = (Boolean)null;\n" + |
11750 |
" public boolean foo(boolean inB) {\n" + |
11751 |
" Boolean b1 = null;\n" + |
11752 |
" X x = new X(b1, null);\n" + |
11753 |
" Boolean b2 = null;\n" + |
11754 |
" boolean dontcare = b2 && inB;\n" + |
11755 |
" Boolean b3 = null;\n" + |
11756 |
" dontcare = inB || b3;\n" + |
11757 |
" Integer dims = null;\n" + |
11758 |
" char[] cs = new char[dims];\n" + |
11759 |
" Boolean b5 = null;\n" + |
11760 |
" do {\n" + |
11761 |
" Boolean b4 = null;\n" + |
11762 |
" for (int i=0;b4; i++);\n" + |
11763 |
" } while (b5);\n" + |
11764 |
" Boolean b6 = null;\n" + |
11765 |
" if (b6) { }\n" + |
11766 |
" Boolean b7 = null;\n" + |
11767 |
" Z z = this.new Z(b7);\n" + |
11768 |
" Integer sel = null;\n" + |
11769 |
" switch(sel) {\n" + |
11770 |
" case 1: break;\n" + |
11771 |
" default: break;\n" + |
11772 |
" }\n" + |
11773 |
" Boolean b8 = null;\n" + |
11774 |
" while (b8) {}\n" + |
11775 |
" Boolean b9 = null;\n" + |
11776 |
" dontcare = (boolean)b9;\n" + |
11777 |
" Boolean b10 = null;\n" + |
11778 |
" assert b10 : \"shouldn't happen, but will\";\n" + |
11779 |
" Boolean b11 = null;\n" + |
11780 |
" return b11;\n" + |
11781 |
" }\n" + |
11782 |
"}"}, |
11783 |
"----------\n" + |
11784 |
"1. ERROR in X.java (at line 4)\n" + |
11785 |
" super(b2 == null, b2);\n" + |
11786 |
" ^^\n" + |
11787 |
"Potential null pointer access: The variable b2 may be null at this location\n" + |
11788 |
"----------\n" + |
11789 |
"2. ERROR in X.java (at line 12)\n" + |
11790 |
" X x = new X(b1, null);\n" + |
11791 |
" ^^\n" + |
11792 |
"Null pointer access: The variable b1 can only be null at this location\n" + |
11793 |
"----------\n" + |
11794 |
"3. ERROR in X.java (at line 14)\n" + |
11795 |
" boolean dontcare = b2 && inB;\n" + |
11796 |
" ^^\n" + |
11797 |
"Null pointer access: The variable b2 can only be null at this location\n" + |
11798 |
"----------\n" + |
11799 |
"4. ERROR in X.java (at line 16)\n" + |
11800 |
" dontcare = inB || b3;\n" + |
11801 |
" ^^\n" + |
11802 |
"Null pointer access: The variable b3 can only be null at this location\n" + |
11803 |
"----------\n" + |
11804 |
"5. ERROR in X.java (at line 18)\n" + |
11805 |
" char[] cs = new char[dims];\n" + |
11806 |
" ^^^^\n" + |
11807 |
"Null pointer access: The variable dims can only be null at this location\n" + |
11808 |
"----------\n" + |
11809 |
"6. ERROR in X.java (at line 22)\n" + |
11810 |
" for (int i=0;b4; i++);\n" + |
11811 |
" ^^\n" + |
11812 |
"Null pointer access: The variable b4 can only be null at this location\n" + |
11813 |
"----------\n" + |
11814 |
"7. ERROR in X.java (at line 23)\n" + |
11815 |
" } while (b5);\n" + |
11816 |
" ^^\n" + |
11817 |
"Null pointer access: The variable b5 can only be null at this location\n" + |
11818 |
"----------\n" + |
11819 |
"8. ERROR in X.java (at line 25)\n" + |
11820 |
" if (b6) { }\n" + |
11821 |
" ^^\n" + |
11822 |
"Null pointer access: The variable b6 can only be null at this location\n" + |
11823 |
"----------\n" + |
11824 |
"9. ERROR in X.java (at line 27)\n" + |
11825 |
" Z z = this.new Z(b7);\n" + |
11826 |
" ^^\n" + |
11827 |
"Null pointer access: The variable b7 can only be null at this location\n" + |
11828 |
"----------\n" + |
11829 |
"10. ERROR in X.java (at line 29)\n" + |
11830 |
" switch(sel) {\n" + |
11831 |
" ^^^\n" + |
11832 |
"Null pointer access: The variable sel can only be null at this location\n" + |
11833 |
"----------\n" + |
11834 |
"11. ERROR in X.java (at line 34)\n" + |
11835 |
" while (b8) {}\n" + |
11836 |
" ^^\n" + |
11837 |
"Null pointer access: The variable b8 can only be null at this location\n" + |
11838 |
"----------\n" + |
11839 |
"12. ERROR in X.java (at line 36)\n" + |
11840 |
" dontcare = (boolean)b9;\n" + |
11841 |
" ^^\n" + |
11842 |
"Null pointer access: The variable b9 can only be null at this location\n" + |
11843 |
"----------\n" + |
11844 |
"13. ERROR in X.java (at line 38)\n" + |
11845 |
" assert b10 : \"shouldn\'t happen, but will\";\n" + |
11846 |
" ^^^\n" + |
11847 |
"Null pointer access: The variable b10 can only be null at this location\n" + |
11848 |
"----------\n" + |
11849 |
"14. ERROR in X.java (at line 40)\n" + |
11850 |
" return b11;\n" + |
11851 |
" ^^^\n" + |
11852 |
"Null pointer access: The variable b11 can only be null at this location\n" + |
11853 |
"----------\n", |
11854 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11855 |
} |
11665 |
} |
11856 |
} |