Lines 11662-11665
Link Here
|
11662 |
"----------\n", |
11662 |
"----------\n", |
11663 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11663 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11664 |
} |
11664 |
} |
|
|
11665 |
|
11666 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment |
11667 |
// LocalDeclaration |
11668 |
public void testBug292478() { |
11669 |
this.runNegativeTest( |
11670 |
new String[] { |
11671 |
"X.java", |
11672 |
"public class X {\n" + |
11673 |
" void foo(Object o) {\n" + |
11674 |
" if (o != null) {/* */}\n" + |
11675 |
" Object p = o;\n" + |
11676 |
" p.toString();\n" + // complain here |
11677 |
" }\n" + |
11678 |
"}"}, |
11679 |
"----------\n" + |
11680 |
"1. ERROR in X.java (at line 5)\n" + |
11681 |
" p.toString();\n" + |
11682 |
" ^\n" + |
11683 |
"Potential null pointer access: The variable p may be null at this location\n" + |
11684 |
"----------\n", |
11685 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11686 |
} |
11687 |
|
11688 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment |
11689 |
// Assignment |
11690 |
public void testBug292478a() { |
11691 |
this.runNegativeTest( |
11692 |
new String[] { |
11693 |
"X.java", |
11694 |
"public class X {\n" + |
11695 |
" void foo(Object o) {\n" + |
11696 |
" Object p;" + |
11697 |
" if (o != null) {/* */}\n" + |
11698 |
" p = o;\n" + |
11699 |
" p.toString();\n" + // complain here |
11700 |
" }\n" + |
11701 |
"}"}, |
11702 |
"----------\n" + |
11703 |
"1. ERROR in X.java (at line 5)\n" + |
11704 |
" p.toString();\n" + |
11705 |
" ^\n" + |
11706 |
"Potential null pointer access: The variable p may be null at this location\n" + |
11707 |
"----------\n", |
11708 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11709 |
} |
11710 |
|
11711 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment |
11712 |
//Assignment after definite null |
11713 |
public void testBug292478b() { |
11714 |
this.runNegativeTest( |
11715 |
new String[] { |
11716 |
"X.java", |
11717 |
"public class X {\n" + |
11718 |
" void foo(Object o) {\n" + |
11719 |
" Object p = null;\n" + |
11720 |
" if (o != null) {/* */}\n" + |
11721 |
" p = o;\n" + |
11722 |
" p.toString();\n" + // complain here |
11723 |
" }\n" + |
11724 |
"}"}, |
11725 |
"----------\n" + |
11726 |
"1. ERROR in X.java (at line 6)\n" + |
11727 |
" p.toString();\n" + |
11728 |
" ^\n" + |
11729 |
"Potential null pointer access: The variable p may be null at this location\n" + |
11730 |
"----------\n", |
11731 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11732 |
} |
11733 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment |
11734 |
//Assignment after definite null - many locals |
11735 |
public void testBug292478c() { |
11736 |
this.runNegativeTest( |
11737 |
new String[] { |
11738 |
"X.java", |
11739 |
"public class X {\n" + |
11740 |
" void foo(Object o) {\n" + |
11741 |
" int i00, i01, i02, i03, i04, i05, i06, i07, i08, i09;\n" + |
11742 |
" int i10, i11, i12, i13, i14, i15, i16, i17, i18, i19;\n" + |
11743 |
" int i20, i21, i22, i23, i24, i25, i26, i27, i28, i29;\n" + |
11744 |
" int i30, i31, i32, i33, i34, i35, i36, i37, i38, i39;\n" + |
11745 |
" int i40, i41, i42, i43, i44, i45, i46, i47, i48, i49;\n" + |
11746 |
" int i50, i51, i52, i53, i54, i55, i56, i57, i58, i59;\n" + |
11747 |
" int i60, i61, i62, i63, i64, i65, i66, i67, i68, i69;\n" + |
11748 |
" Object p = null;\n" + |
11749 |
" if (o != null) {/* */}\n" + |
11750 |
" p = o;\n" + |
11751 |
" p.toString();\n" + // complain here |
11752 |
" }\n" + |
11753 |
"}"}, |
11754 |
"----------\n" + |
11755 |
"1. ERROR in X.java (at line 13)\n" + |
11756 |
" p.toString();\n" + |
11757 |
" ^\n" + |
11758 |
"Potential null pointer access: The variable p may be null at this location\n" + |
11759 |
"----------\n", |
11760 |
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); |
11761 |
} |
11762 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment |
11763 |
//Assignment affects initsOnFinally |
11764 |
public void testBug292478d() { |
11765 |
this.runNegativeTest( |
11766 |
new String[] { |
11767 |
"X.java", |
11768 |
"public class X {\n" + |
11769 |
" X bar() {\n" + |
11770 |
" return null;\n" + |
11771 |
" }\n" + |
11772 |
" Object foo() {\n" + |
11773 |
" X x = null;\n" + |
11774 |
" X y = new X();\n" + |
11775 |
" X u = null;\n" + |
11776 |
" try {\n" + |
11777 |
" u = bar();\n" + |
11778 |
" x = bar();\n" + |
11779 |
" if (x==null) { }\n" + |
11780 |
" y = x;\n" + // this makes y potentially null |
11781 |
" if (x==null) { y=bar();} else { y=new X(); }\n" + |
11782 |
" return x;\n" + |
11783 |
" } finally {\n" + |
11784 |
" y.toString();\n" + // must complain against potentially null, although normal exist of tryBlock says differently (unknown or non-null) |
11785 |
" }\n" + |
11786 |
" }\n" + |
11787 |
"}\n"}, |
11788 |
"----------\n" + |
11789 |
"1. ERROR in X.java (at line 17)\n" + |
11790 |
" y.toString();\n" + |
11791 |
" ^\n" + |
11792 |
"Potential null pointer access: The variable y may be null at this location\n" + |
11793 |
"----------\n"); |
11794 |
} |
11665 |
} |
11795 |
} |