Lines 11715-11718
Link Here
|
11715 |
" 24 return\n"; |
11715 |
" 24 return\n"; |
11716 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
11716 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
11717 |
} |
11717 |
} |
|
|
11718 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 |
11719 |
// unboxing raises an NPE |
11720 |
// LocalDeclaration |
11721 |
public void testBug319201() { |
11722 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
11723 |
return; |
11724 |
runNegativeTest( |
11725 |
new String[] { |
11726 |
"X.java", |
11727 |
"public class X {\n" + |
11728 |
" public void foo() {\n" + |
11729 |
" Integer i = null;\n" + |
11730 |
" int j = i;\n" + // should warn |
11731 |
" }\n" + |
11732 |
"}"}, |
11733 |
"----------\n" + |
11734 |
"1. ERROR in X.java (at line 4)\n" + |
11735 |
" int j = i;\n" + |
11736 |
" ^\n" + |
11737 |
"Null pointer access: The variable i can only be null at this location\n" + |
11738 |
"----------\n", |
11739 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11740 |
} |
11741 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 |
11742 |
// unboxing could raise an NPE |
11743 |
// Assignment |
11744 |
public void testBug319201a() { |
11745 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
11746 |
return; |
11747 |
runNegativeTest( |
11748 |
new String[] { |
11749 |
"X.java", |
11750 |
"public class X {\n" + |
11751 |
" public void foo(Integer i) {\n" + |
11752 |
" if (i == null) {};\n" + |
11753 |
" int j;\n" + |
11754 |
" j = i;\n" + // should warn |
11755 |
" }\n" + |
11756 |
"}"}, |
11757 |
"----------\n" + |
11758 |
"1. ERROR in X.java (at line 5)\n" + |
11759 |
" j = i;\n" + |
11760 |
" ^\n" + |
11761 |
"Potential null pointer access: The variable i may be null at this location\n" + |
11762 |
"----------\n", |
11763 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11764 |
} |
11765 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 |
11766 |
// unboxing raises an NPE |
11767 |
// MessageSend |
11768 |
public void testBug319201b() { |
11769 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
11770 |
return; |
11771 |
runNegativeTest( |
11772 |
new String[] { |
11773 |
"X.java", |
11774 |
"public class X {\n" + |
11775 |
" public void foo() {\n" + |
11776 |
" Boolean bo = null;;\n" + |
11777 |
" bar(bo);\n" + // should warn |
11778 |
" }\n" + |
11779 |
" void bar(boolean b) {}\n" + |
11780 |
"}"}, |
11781 |
"----------\n" + |
11782 |
"1. ERROR in X.java (at line 4)\n" + |
11783 |
" bar(bo);\n" + |
11784 |
" ^^\n" + |
11785 |
"Null pointer access: The variable bo can only be null at this location\n" + |
11786 |
"----------\n", |
11787 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11788 |
} |
11789 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 |
11790 |
// unboxing raises an NPE |
11791 |
// Node types covered (in this order): |
11792 |
// ExplicitConstructorCall |
11793 |
// AllocationExpression |
11794 |
// AND_AND_Expression |
11795 |
// OR_OR_Expression |
11796 |
// ArrayAllocationExpression |
11797 |
// ForStatement |
11798 |
// DoStatement |
11799 |
// IfStatement |
11800 |
// QualifiedAllocationExpression |
11801 |
// SwitchStatement |
11802 |
// WhileStatement |
11803 |
// CastExpression |
11804 |
// AssertStatement |
11805 |
// ReturnStatement |
11806 |
public void testBug319201c() { |
11807 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
11808 |
return; |
11809 |
runNegativeTest( |
11810 |
new String[] { |
11811 |
"X.java", |
11812 |
"class Y { public Y(boolean b1, boolean b2) {} }\n" + |
11813 |
"public class X extends Y {\n" + |
11814 |
" public X(boolean b, Boolean b2) {\n" + |
11815 |
" super(b2 == null, b2);\n" + |
11816 |
" }\n" + |
11817 |
" class Z {\n" + |
11818 |
" public Z(boolean b) {}\n" + |
11819 |
" }\n" + |
11820 |
" boolean fB = (Boolean)null;\n" + |
11821 |
" public boolean foo(boolean inB) {\n" + |
11822 |
" Boolean b1 = null;\n" + |
11823 |
" X x = new X(b1, null);\n" + |
11824 |
" Boolean b2 = null;\n" + |
11825 |
" boolean dontcare = b2 && inB;\n" + |
11826 |
" Boolean b3 = null;\n" + |
11827 |
" dontcare = inB || b3;\n" + |
11828 |
" Integer dims = null;\n" + |
11829 |
" char[] cs = new char[dims];\n" + |
11830 |
" Boolean b5 = null;\n" + |
11831 |
" do {\n" + |
11832 |
" Boolean b4 = null;\n" + |
11833 |
" for (int i=0;b4; i++);\n" + |
11834 |
" } while (b5);\n" + |
11835 |
" Boolean b6 = null;\n" + |
11836 |
" if (b6) { }\n" + |
11837 |
" Boolean b7 = null;\n" + |
11838 |
" Z z = this.new Z(b7);\n" + |
11839 |
" Integer sel = null;\n" + |
11840 |
" switch(sel) {\n" + |
11841 |
" case 1: break;\n" + |
11842 |
" default: break;\n" + |
11843 |
" }\n" + |
11844 |
" Boolean b8 = null;\n" + |
11845 |
" while (b8) {}\n" + |
11846 |
" Boolean b9 = null;\n" + |
11847 |
" dontcare = (boolean)b9;\n" + |
11848 |
" Boolean b10 = null;\n" + |
11849 |
" assert b10 : \"shouldn't happen, but will\";\n" + |
11850 |
" Boolean b11 = null;\n" + |
11851 |
" return b11;\n" + |
11852 |
" }\n" + |
11853 |
"}"}, |
11854 |
"----------\n" + |
11855 |
"1. ERROR in X.java (at line 4)\n" + |
11856 |
" super(b2 == null, b2);\n" + |
11857 |
" ^^\n" + |
11858 |
"Potential null pointer access: The variable b2 may be null at this location\n" + |
11859 |
"----------\n" + |
11860 |
"2. ERROR in X.java (at line 12)\n" + |
11861 |
" X x = new X(b1, null);\n" + |
11862 |
" ^^\n" + |
11863 |
"Null pointer access: The variable b1 can only be null at this location\n" + |
11864 |
"----------\n" + |
11865 |
"3. ERROR in X.java (at line 14)\n" + |
11866 |
" boolean dontcare = b2 && inB;\n" + |
11867 |
" ^^\n" + |
11868 |
"Null pointer access: The variable b2 can only be null at this location\n" + |
11869 |
"----------\n" + |
11870 |
"4. ERROR in X.java (at line 16)\n" + |
11871 |
" dontcare = inB || b3;\n" + |
11872 |
" ^^\n" + |
11873 |
"Null pointer access: The variable b3 can only be null at this location\n" + |
11874 |
"----------\n" + |
11875 |
"5. ERROR in X.java (at line 18)\n" + |
11876 |
" char[] cs = new char[dims];\n" + |
11877 |
" ^^^^\n" + |
11878 |
"Null pointer access: The variable dims can only be null at this location\n" + |
11879 |
"----------\n" + |
11880 |
"6. ERROR in X.java (at line 22)\n" + |
11881 |
" for (int i=0;b4; i++);\n" + |
11882 |
" ^^\n" + |
11883 |
"Null pointer access: The variable b4 can only be null at this location\n" + |
11884 |
"----------\n" + |
11885 |
"7. ERROR in X.java (at line 23)\n" + |
11886 |
" } while (b5);\n" + |
11887 |
" ^^\n" + |
11888 |
"Null pointer access: The variable b5 can only be null at this location\n" + |
11889 |
"----------\n" + |
11890 |
"8. ERROR in X.java (at line 25)\n" + |
11891 |
" if (b6) { }\n" + |
11892 |
" ^^\n" + |
11893 |
"Null pointer access: The variable b6 can only be null at this location\n" + |
11894 |
"----------\n" + |
11895 |
"9. ERROR in X.java (at line 27)\n" + |
11896 |
" Z z = this.new Z(b7);\n" + |
11897 |
" ^^\n" + |
11898 |
"Null pointer access: The variable b7 can only be null at this location\n" + |
11899 |
"----------\n" + |
11900 |
"10. ERROR in X.java (at line 29)\n" + |
11901 |
" switch(sel) {\n" + |
11902 |
" ^^^\n" + |
11903 |
"Null pointer access: The variable sel can only be null at this location\n" + |
11904 |
"----------\n" + |
11905 |
"11. ERROR in X.java (at line 34)\n" + |
11906 |
" while (b8) {}\n" + |
11907 |
" ^^\n" + |
11908 |
"Null pointer access: The variable b8 can only be null at this location\n" + |
11909 |
"----------\n" + |
11910 |
"12. ERROR in X.java (at line 36)\n" + |
11911 |
" dontcare = (boolean)b9;\n" + |
11912 |
" ^^\n" + |
11913 |
"Null pointer access: The variable b9 can only be null at this location\n" + |
11914 |
"----------\n" + |
11915 |
"13. ERROR in X.java (at line 38)\n" + |
11916 |
" assert b10 : \"shouldn\'t happen, but will\";\n" + |
11917 |
" ^^^\n" + |
11918 |
"Null pointer access: The variable b10 can only be null at this location\n" + |
11919 |
"----------\n" + |
11920 |
"14. ERROR in X.java (at line 40)\n" + |
11921 |
" return b11;\n" + |
11922 |
" ^^^\n" + |
11923 |
"Null pointer access: The variable b11 can only be null at this location\n" + |
11924 |
"----------\n", |
11925 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11926 |
} |
11927 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 |
11928 |
// unboxing raises an NPE |
11929 |
// DoStatement, variants with assignement in the body & empty body |
11930 |
public void testBug319201d() { |
11931 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
11932 |
return; |
11933 |
runNegativeTest( |
11934 |
new String[] { |
11935 |
"X.java", |
11936 |
"public class X {\n" + |
11937 |
" public void foo(boolean cond, boolean cond2) {\n" + |
11938 |
" Boolean b = null;\n" + |
11939 |
" do {\n" + |
11940 |
" b = false;\n" + |
11941 |
" if (cond) continue;\n" + // shouldn't make a difference |
11942 |
" } while (b);\n" + // don't complain, loop body has already assigned b |
11943 |
" Boolean b2 = null;\n" + |
11944 |
" do {\n" + |
11945 |
" if (cond) continue;\n" + |
11946 |
" b2 = false;\n" + |
11947 |
" } while (b2);\n" + // complain here: potentially null |
11948 |
" Boolean b3 = null;\n" + |
11949 |
" do {\n" + |
11950 |
" } while (b3);\n" + // complain here: definitely null |
11951 |
" Boolean b4 = null;\n" + |
11952 |
" do {\n" + |
11953 |
" if (cond) {\n" + |
11954 |
" b4 = true;\n" + |
11955 |
" if (cond2) continue;\n" + |
11956 |
" }\n" + |
11957 |
" b4 = false;\n" + |
11958 |
" } while (b4);\n" + // don't complain here: definitely non-null |
11959 |
" Boolean b5 = null;\n" + |
11960 |
" do {\n" + |
11961 |
" b5 = true;\n" + |
11962 |
" } while (b5);\n" + // don't complain |
11963 |
" Boolean b6 = null;\n" + |
11964 |
" do {\n" + |
11965 |
" b6 = true;\n" + |
11966 |
" continue;\n" + |
11967 |
" } while (b6); \n" + // don't complain |
11968 |
" }\n" + |
11969 |
"}"}, |
11970 |
"----------\n" + |
11971 |
"1. ERROR in X.java (at line 12)\n" + |
11972 |
" } while (b2);\n" + |
11973 |
" ^^\n" + |
11974 |
"Potential null pointer access: The variable b2 may be null at this location\n" + |
11975 |
"----------\n" + |
11976 |
"2. ERROR in X.java (at line 15)\n" + |
11977 |
" } while (b3);\n" + |
11978 |
" ^^\n" + |
11979 |
"Null pointer access: The variable b3 can only be null at this location\n" + |
11980 |
"----------\n", |
11981 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11982 |
} |
11718 |
} |
11983 |
} |