Lines 2114-2119
Link Here
|
2114 |
"----------\n"); |
2114 |
"----------\n"); |
2115 |
} |
2115 |
} |
2116 |
|
2116 |
|
|
|
2117 |
// null analysis - if/else |
2118 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128014 |
2119 |
// invalid analysis when redundant check is done |
2120 |
public void test0333_if_else() { |
2121 |
this.runNegativeTest( |
2122 |
new String[] { |
2123 |
"X.java", |
2124 |
"public class X {\n" + |
2125 |
" void foo(Object o) {\n" + |
2126 |
" o = new Object();\n" + |
2127 |
" if (o != null) {\n" + // complain |
2128 |
" o.toString();\n" + |
2129 |
" }\n" + |
2130 |
" o.toString();\n" + // quiet asked |
2131 |
" }\n" + |
2132 |
"}"}, |
2133 |
"----------\n" + |
2134 |
"1. ERROR in X.java (at line 4)\n" + |
2135 |
" if (o != null) {\n" + |
2136 |
" ^\n" + |
2137 |
"The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + |
2138 |
"----------\n"); |
2139 |
} |
2140 |
|
2141 |
// null analysis - if/else |
2142 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128014 |
2143 |
// invalid analysis when redundant check is done - variant |
2144 |
public void test0334_if_else() { |
2145 |
this.runNegativeTest( |
2146 |
new String[] { |
2147 |
"X.java", |
2148 |
"public class X {\n" + |
2149 |
" void foo(Object o) {\n" + |
2150 |
" o = new Object();\n" + |
2151 |
" if (o != null) {\n" + // complain |
2152 |
" o.toString();\n" + |
2153 |
" }\n" + |
2154 |
" else {\n" + |
2155 |
" o.toString();\n" + // must complain anyway (could be quite distant from the if test) |
2156 |
" }\n" + |
2157 |
" o.toString();\n" + // quiet |
2158 |
" }\n" + |
2159 |
"}"}, |
2160 |
"----------\n" + |
2161 |
"1. ERROR in X.java (at line 4)\n" + |
2162 |
" if (o != null) {\n" + |
2163 |
" ^\n" + |
2164 |
"The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + |
2165 |
"----------\n" + |
2166 |
"2. ERROR in X.java (at line 8)\n" + |
2167 |
" o.toString();\n" + |
2168 |
" ^\n" + |
2169 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
2170 |
"----------\n"); |
2171 |
} |
2172 |
|
2173 |
// null analysis - if/else |
2174 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=129581 |
2175 |
// this is a limit of the fix for bug 128014 - calls for a nuance |
2176 |
// between potential null and tainted null |
2177 |
public void _test0335_if_else() { |
2178 |
this.runNegativeTest( |
2179 |
new String[] { |
2180 |
"X.java", |
2181 |
"public class X {\n" + |
2182 |
" void foo(Object o) {\n" + |
2183 |
" if (o != null) {\n" + |
2184 |
" if (o != null) {\n" + // complain |
2185 |
" o.toString();\n" + |
2186 |
" }\n" + |
2187 |
" o.toString();\n" + // quiet |
2188 |
" }\n" + |
2189 |
" }\n" + |
2190 |
"}"}, |
2191 |
"----------\n" + |
2192 |
"1. ERROR in X.java (at line 4)\n" + |
2193 |
" if (o != null) {\n" + |
2194 |
" ^\n" + |
2195 |
"The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + |
2196 |
"----------\n"); |
2197 |
} |
2198 |
|
2199 |
// null analysis - if/else |
2200 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128014 |
2201 |
// invalid analysis when redundant check is done - variant |
2202 |
public void test0336_if_else() { |
2203 |
this.runNegativeTest( |
2204 |
new String[] { |
2205 |
"X.java", |
2206 |
"public class X {\n" + |
2207 |
" void foo(Object o) {\n" + |
2208 |
" if (o != null) {\n" + |
2209 |
" if (o != null) {\n" + // complain |
2210 |
" o.toString();\n" + |
2211 |
" }\n" + |
2212 |
" else {\n" + |
2213 |
" o.toString();\n" + // must complain anyway (could be quite distant from the if test) |
2214 |
" }\n" + |
2215 |
" o.toString();\n" + // quiet |
2216 |
" }\n" + |
2217 |
" }\n" + |
2218 |
"}"}, |
2219 |
"----------\n" + |
2220 |
"1. ERROR in X.java (at line 4)\n" + |
2221 |
" if (o != null) {\n" + |
2222 |
" ^\n" + |
2223 |
"The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + |
2224 |
"----------\n" + |
2225 |
"2. ERROR in X.java (at line 8)\n" + |
2226 |
" o.toString();\n" + |
2227 |
" ^\n" + |
2228 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
2229 |
"----------\n"); |
2230 |
} |
2231 |
|
2117 |
// null analysis -- while |
2232 |
// null analysis -- while |
2118 |
public void test0401_while() { |
2233 |
public void test0401_while() { |
2119 |
this.runNegativeTest( |
2234 |
this.runNegativeTest( |
Lines 2603-2609
Link Here
|
2603 |
} |
2718 |
} |
2604 |
|
2719 |
|
2605 |
// null analysis -- while |
2720 |
// null analysis -- while |
2606 |
// the second message looks a bit strange |
|
|
2607 |
public void test0423_while() { |
2721 |
public void test0423_while() { |
2608 |
this.runNegativeTest( |
2722 |
this.runNegativeTest( |
2609 |
new String[] { |
2723 |
new String[] { |
Lines 2624-2634
Link Here
|
2624 |
" if (o == null) { /* */ }\n" + |
2738 |
" if (o == null) { /* */ }\n" + |
2625 |
" ^\n" + |
2739 |
" ^\n" + |
2626 |
"The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + |
2740 |
"The variable o cannot be null; it was either set to a non-null value or assumed to be non-null when last used\n" + |
2627 |
"----------\n" + |
|
|
2628 |
"2. ERROR in X.java (at line 8)\n" + |
2629 |
" o = null;\n" + |
2630 |
" ^\n" + |
2631 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
2632 |
"----------\n"); |
2741 |
"----------\n"); |
2633 |
} |
2742 |
} |
2634 |
|
2743 |
|
Lines 8241-8247
Link Here
|
8241 |
{{0,1,0,0},{0,0,1,1},{0,0,1,1}}, |
8350 |
{{0,1,0,0},{0,0,1,1},{0,0,1,1}}, |
8242 |
{{0,1,0,0},{0,1,0,0},{0,1,0,0}}, |
8351 |
{{0,1,0,0},{0,1,0,0},{0,1,0,0}}, |
8243 |
{{0,1,0,0},{0,1,1,0},{0,1,1,0}}, |
8352 |
{{0,1,0,0},{0,1,1,0},{0,1,1,0}}, |
8244 |
{{0,1,0,0},{1,0,0,1},{0,0,1,1}}, |
8353 |
{{0,1,0,0},{1,0,0,1},{0,0,0,1}}, |
8245 |
{{0,1,0,0},{1,0,1,0},{0,1,1,0}}, |
8354 |
{{0,1,0,0},{1,0,1,0},{0,1,1,0}}, |
8246 |
{{0,1,0,0},{1,0,1,1},{0,0,1,1}}, |
8355 |
{{0,1,0,0},{1,0,1,1},{0,0,1,1}}, |
8247 |
{{0,1,0,0},{1,1,0,0},{0,0,1,0}}, |
8356 |
{{0,1,0,0},{1,1,0,0},{0,0,1,0}}, |
Lines 8261-8267
Link Here
|
8261 |
{{1,0,0,1},{0,0,0,1},{0,0,0,1}}, |
8370 |
{{1,0,0,1},{0,0,0,1},{0,0,0,1}}, |
8262 |
{{1,0,0,1},{0,0,1,0},{0,0,1,1}}, |
8371 |
{{1,0,0,1},{0,0,1,0},{0,0,1,1}}, |
8263 |
{{1,0,0,1},{0,0,1,1},{0,0,1,1}}, |
8372 |
{{1,0,0,1},{0,0,1,1},{0,0,1,1}}, |
8264 |
{{1,0,0,1},{0,1,0,0},{0,0,1,1}}, |
8373 |
{{1,0,0,1},{0,1,0,0},{0,0,0,1}}, |
8265 |
{{1,0,0,1},{0,1,1,0},{0,0,1,1}}, |
8374 |
{{1,0,0,1},{0,1,1,0},{0,0,1,1}}, |
8266 |
{{1,0,0,1},{1,0,0,1},{1,0,0,1}}, |
8375 |
{{1,0,0,1},{1,0,0,1},{1,0,0,1}}, |
8267 |
{{1,0,0,1},{1,0,1,0},{0,0,1,1}}, |
8376 |
{{1,0,0,1},{1,0,1,0},{0,0,1,1}}, |