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 |
// LocalDeclaration |
11668 |
public void testBug319201() { |
11669 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
11670 |
return; |
11671 |
runNegativeTest( |
11672 |
new String[] { |
11673 |
"X.java", |
11674 |
"public class X {\n" + |
11675 |
" public void foo() {\n" + |
11676 |
" Integer i = null;\n" + |
11677 |
" int j = i;\n" + // should warn |
11678 |
" }\n" + |
11679 |
"}"}, |
11680 |
"----------\n" + |
11681 |
"1. ERROR in X.java (at line 4)\n" + |
11682 |
" int j = i;\n" + |
11683 |
" ^\n" + |
11684 |
"Null pointer access: The variable i can only be null at this location\n" + |
11685 |
"----------\n", |
11686 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11687 |
} |
11688 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 |
11689 |
// unboxing could raise an NPE |
11690 |
// Assignment |
11691 |
public void testBug319201a() { |
11692 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
11693 |
return; |
11694 |
runNegativeTest( |
11695 |
new String[] { |
11696 |
"X.java", |
11697 |
"public class X {\n" + |
11698 |
" public void foo(Integer i) {\n" + |
11699 |
" if (i == null) {};\n" + |
11700 |
" int j;\n" + |
11701 |
" j = i;\n" + // should warn |
11702 |
" }\n" + |
11703 |
"}"}, |
11704 |
"----------\n" + |
11705 |
"1. ERROR in X.java (at line 5)\n" + |
11706 |
" j = i;\n" + |
11707 |
" ^\n" + |
11708 |
"Potential null pointer access: The variable i may be null at this location\n" + |
11709 |
"----------\n", |
11710 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11711 |
} |
11712 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 |
11713 |
// unboxing raises an NPE |
11714 |
// MessageSend |
11715 |
public void testBug319201b() { |
11716 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
11717 |
return; |
11718 |
runNegativeTest( |
11719 |
new String[] { |
11720 |
"X.java", |
11721 |
"public class X {\n" + |
11722 |
" public void foo() {\n" + |
11723 |
" Boolean bo = null;;\n" + |
11724 |
" bar(bo);\n" + // should warn |
11725 |
" }\n" + |
11726 |
" void bar(boolean b) {}\n" + |
11727 |
"}"}, |
11728 |
"----------\n" + |
11729 |
"1. ERROR in X.java (at line 4)\n" + |
11730 |
" bar(bo);\n" + |
11731 |
" ^^\n" + |
11732 |
"Null pointer access: The variable bo can only be null at this location\n" + |
11733 |
"----------\n", |
11734 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11735 |
} |
11736 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 |
11737 |
// unboxing raises an NPE |
11738 |
// Node types covered (in this order): |
11739 |
// ExplicitConstructorCall |
11740 |
// AllocationExpression |
11741 |
// AND_AND_Expression |
11742 |
// OR_OR_Expression |
11743 |
// ArrayAllocationExpression |
11744 |
// ForStatement |
11745 |
// DoStatement |
11746 |
// IfStatement |
11747 |
// QualifiedAllocationExpression |
11748 |
// SwitchStatement |
11749 |
// WhileStatement |
11750 |
// CastExpression |
11751 |
// AssertStatement |
11752 |
// ReturnStatement |
11753 |
public void testBug319201c() { |
11754 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
11755 |
return; |
11756 |
runNegativeTest( |
11757 |
new String[] { |
11758 |
"X.java", |
11759 |
"class Y { public Y(boolean b1, boolean b2) {} }\n" + |
11760 |
"public class X extends Y {\n" + |
11761 |
" public X(boolean b, Boolean b2) {\n" + |
11762 |
" super(b2 == null, b2);\n" + |
11763 |
" }\n" + |
11764 |
" class Z {\n" + |
11765 |
" public Z(boolean b) {}\n" + |
11766 |
" }\n" + |
11767 |
" boolean fB = (Boolean)null;\n" + |
11768 |
" public boolean foo(boolean inB) {\n" + |
11769 |
" Boolean b1 = null;\n" + |
11770 |
" X x = new X(b1, null);\n" + |
11771 |
" Boolean b2 = null;\n" + |
11772 |
" boolean dontcare = b2 && inB;\n" + |
11773 |
" Boolean b3 = null;\n" + |
11774 |
" dontcare = inB || b3;\n" + |
11775 |
" Integer dims = null;\n" + |
11776 |
" char[] cs = new char[dims];\n" + |
11777 |
" Boolean b5 = null;\n" + |
11778 |
" do {\n" + |
11779 |
" Boolean b4 = null;\n" + |
11780 |
" for (int i=0;b4; i++);\n" + |
11781 |
" } while (b5);\n" + |
11782 |
" Boolean b6 = null;\n" + |
11783 |
" if (b6) { }\n" + |
11784 |
" Boolean b7 = null;\n" + |
11785 |
" Z z = this.new Z(b7);\n" + |
11786 |
" Integer sel = null;\n" + |
11787 |
" switch(sel) {\n" + |
11788 |
" case 1: break;\n" + |
11789 |
" default: break;\n" + |
11790 |
" }\n" + |
11791 |
" Boolean b8 = null;\n" + |
11792 |
" while (b8) {}\n" + |
11793 |
" Boolean b9 = null;\n" + |
11794 |
" dontcare = (boolean)b9;\n" + |
11795 |
" Boolean b10 = null;\n" + |
11796 |
" assert b10 : \"shouldn't happen, but will\";\n" + |
11797 |
" Boolean b11 = null;\n" + |
11798 |
" return b11;\n" + |
11799 |
" }\n" + |
11800 |
"}"}, |
11801 |
"----------\n" + |
11802 |
"1. ERROR in X.java (at line 4)\n" + |
11803 |
" super(b2 == null, b2);\n" + |
11804 |
" ^^\n" + |
11805 |
"Potential null pointer access: The variable b2 may be null at this location\n" + |
11806 |
"----------\n" + |
11807 |
"2. ERROR in X.java (at line 12)\n" + |
11808 |
" X x = new X(b1, null);\n" + |
11809 |
" ^^\n" + |
11810 |
"Null pointer access: The variable b1 can only be null at this location\n" + |
11811 |
"----------\n" + |
11812 |
"3. ERROR in X.java (at line 14)\n" + |
11813 |
" boolean dontcare = b2 && inB;\n" + |
11814 |
" ^^\n" + |
11815 |
"Null pointer access: The variable b2 can only be null at this location\n" + |
11816 |
"----------\n" + |
11817 |
"4. ERROR in X.java (at line 16)\n" + |
11818 |
" dontcare = inB || b3;\n" + |
11819 |
" ^^\n" + |
11820 |
"Null pointer access: The variable b3 can only be null at this location\n" + |
11821 |
"----------\n" + |
11822 |
"5. ERROR in X.java (at line 18)\n" + |
11823 |
" char[] cs = new char[dims];\n" + |
11824 |
" ^^^^\n" + |
11825 |
"Null pointer access: The variable dims can only be null at this location\n" + |
11826 |
"----------\n" + |
11827 |
"6. ERROR in X.java (at line 22)\n" + |
11828 |
" for (int i=0;b4; i++);\n" + |
11829 |
" ^^\n" + |
11830 |
"Null pointer access: The variable b4 can only be null at this location\n" + |
11831 |
"----------\n" + |
11832 |
"7. ERROR in X.java (at line 23)\n" + |
11833 |
" } while (b5);\n" + |
11834 |
" ^^\n" + |
11835 |
"Null pointer access: The variable b5 can only be null at this location\n" + |
11836 |
"----------\n" + |
11837 |
"8. ERROR in X.java (at line 25)\n" + |
11838 |
" if (b6) { }\n" + |
11839 |
" ^^\n" + |
11840 |
"Null pointer access: The variable b6 can only be null at this location\n" + |
11841 |
"----------\n" + |
11842 |
"9. ERROR in X.java (at line 27)\n" + |
11843 |
" Z z = this.new Z(b7);\n" + |
11844 |
" ^^\n" + |
11845 |
"Null pointer access: The variable b7 can only be null at this location\n" + |
11846 |
"----------\n" + |
11847 |
"10. ERROR in X.java (at line 29)\n" + |
11848 |
" switch(sel) {\n" + |
11849 |
" ^^^\n" + |
11850 |
"Null pointer access: The variable sel can only be null at this location\n" + |
11851 |
"----------\n" + |
11852 |
"11. ERROR in X.java (at line 34)\n" + |
11853 |
" while (b8) {}\n" + |
11854 |
" ^^\n" + |
11855 |
"Null pointer access: The variable b8 can only be null at this location\n" + |
11856 |
"----------\n" + |
11857 |
"12. ERROR in X.java (at line 36)\n" + |
11858 |
" dontcare = (boolean)b9;\n" + |
11859 |
" ^^\n" + |
11860 |
"Null pointer access: The variable b9 can only be null at this location\n" + |
11861 |
"----------\n" + |
11862 |
"13. ERROR in X.java (at line 38)\n" + |
11863 |
" assert b10 : \"shouldn\'t happen, but will\";\n" + |
11864 |
" ^^^\n" + |
11865 |
"Null pointer access: The variable b10 can only be null at this location\n" + |
11866 |
"----------\n" + |
11867 |
"14. ERROR in X.java (at line 40)\n" + |
11868 |
" return b11;\n" + |
11869 |
" ^^^\n" + |
11870 |
"Null pointer access: The variable b11 can only be null at this location\n" + |
11871 |
"----------\n", |
11872 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11873 |
} |
11874 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 |
11875 |
// unboxing raises an NPE |
11876 |
// DoStatement, variants with assignement in the body & empty body |
11877 |
public void testBug319201d() { |
11878 |
if (this.complianceLevel < ClassFileConstants.JDK1_5) |
11879 |
return; |
11880 |
runNegativeTest( |
11881 |
new String[] { |
11882 |
"X.java", |
11883 |
"public class X {\n" + |
11884 |
" public void foo(boolean cond, boolean cond2) {\n" + |
11885 |
" Boolean b = null;\n" + |
11886 |
" do {\n" + |
11887 |
" b = false;\n" + |
11888 |
" if (cond) continue;\n" + // shouldn't make a difference |
11889 |
" } while (b);\n" + // don't complain, loop body has already assigned b |
11890 |
" Boolean b2 = null;\n" + |
11891 |
" do {\n" + |
11892 |
" if (cond) continue;\n" + |
11893 |
" b2 = false;\n" + |
11894 |
" } while (b2);\n" + // complain here: potentially null |
11895 |
" Boolean b3 = null;\n" + |
11896 |
" do {\n" + |
11897 |
" } while (b3);\n" + // complain here: definitely null |
11898 |
" Boolean b4 = null;\n" + |
11899 |
" do {\n" + |
11900 |
" if (cond) {\n" + |
11901 |
" b4 = true;\n" + |
11902 |
" if (cond2) continue;\n" + |
11903 |
" }\n" + |
11904 |
" b4 = false;\n" + |
11905 |
" } while (b4);\n" + // don't complain here: definitely non-null |
11906 |
" }\n" + |
11907 |
"}"}, |
11908 |
"----------\n" + |
11909 |
"1. ERROR in X.java (at line 12)\n" + |
11910 |
" } while (b2);\n" + |
11911 |
" ^^\n" + |
11912 |
"Potential null pointer access: The variable b2 may be null at this location\n" + |
11913 |
"----------\n" + |
11914 |
"2. ERROR in X.java (at line 15)\n" + |
11915 |
" } while (b3);\n" + |
11916 |
" ^^\n" + |
11917 |
"Null pointer access: The variable b3 can only be null at this location\n" + |
11918 |
"----------\n", |
11919 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11920 |
} |
11665 |
} |
11921 |
} |