Lines 14898-14901
Link Here
|
14898 |
"----------\n"); |
14898 |
"----------\n"); |
14899 |
} |
14899 |
} |
14900 |
} |
14900 |
} |
|
|
14901 |
// Bug 354554 - [null] conditional with redundant condition yields weak error message |
14902 |
public void testBug354554() { |
14903 |
this.runNegativeTest( |
14904 |
new String[] { |
14905 |
"Bug354554.java", |
14906 |
"public class Bug354554{\n" + |
14907 |
" void foo() {\n" + |
14908 |
" Object u = new Object();\n" + |
14909 |
" Object r = (u == null ? u : null);\n" + // condition is always false - should not spoil subsequent null-analysis |
14910 |
" System.out.println(r.toString());\n" + // should strongly complain: r is definitely null |
14911 |
" }\n" + |
14912 |
"}\n" |
14913 |
}, |
14914 |
"----------\n" + |
14915 |
"1. ERROR in Bug354554.java (at line 4)\n" + |
14916 |
" Object r = (u == null ? u : null);\n" + |
14917 |
" ^\n" + |
14918 |
"Null comparison always yields false: The variable u cannot be null at this location\n" + |
14919 |
"----------\n" + |
14920 |
"2. ERROR in Bug354554.java (at line 5)\n" + |
14921 |
" System.out.println(r.toString());\n" + |
14922 |
" ^\n" + |
14923 |
"Null pointer access: The variable r can only be null at this location\n" + |
14924 |
"----------\n"); |
14925 |
} |
14926 |
//Bug 354554 - [null] conditional with redundant condition yields weak error message |
14927 |
public void testBug354554b() { |
14928 |
this.runNegativeTest( |
14929 |
new String[] { |
14930 |
"Bug354554.java", |
14931 |
"public class Bug354554{\n" + |
14932 |
" void foo() {\n" + |
14933 |
" Object u = new Object();\n" + |
14934 |
" Object r = (u != null ? u : null);\n" + // condition is always true - should not spoil subsequent null-analysis |
14935 |
" System.out.println(r.toString());\n" + // don't complain: r is definitely non-null |
14936 |
" }\n" + |
14937 |
"}\n" |
14938 |
}, |
14939 |
"----------\n" + |
14940 |
"1. ERROR in Bug354554.java (at line 4)\n" + |
14941 |
" Object r = (u != null ? u : null);\n" + |
14942 |
" ^\n" + |
14943 |
"Redundant null check: The variable u cannot be null at this location\n" + |
14944 |
"----------\n"); |
14945 |
} |
14901 |
} |
14946 |
} |