Lines 33-43
Link Here
|
33 |
// -Dcompliance=1.4 (for example) to lower it if needed |
33 |
// -Dcompliance=1.4 (for example) to lower it if needed |
34 |
static { |
34 |
static { |
35 |
// TESTS_NAMES = new String[] { "test011" }; |
35 |
// TESTS_NAMES = new String[] { "test011" }; |
36 |
// TESTS_NUMBERS = new int[] { 729 }; |
36 |
// TESTS_NUMBERS = new int[] { 48 }; |
37 |
// TESTS_NUMBERS = new int[] { 2999 }; |
37 |
// TESTS_NUMBERS = new int[] { 2999 }; |
38 |
// TESTS_RANGE = new int[] { 2050, -1 }; |
38 |
// TESTS_RANGE = new int[] { 2050, -1 }; |
39 |
// TESTS_RANGE = new int[] { 1, 2049 }; |
39 |
// TESTS_RANGE = new int[] { 1, 2049 }; |
40 |
// TESTS_RANGE = new int[] { 449, 451 }; |
40 |
TESTS_RANGE = new int[] { 120, 130 }; |
41 |
// TESTS_RANGE = new int[] { 900, 999 }; |
41 |
// TESTS_RANGE = new int[] { 900, 999 }; |
42 |
} |
42 |
} |
43 |
|
43 |
|
Lines 853-910
Link Here
|
853 |
""); |
853 |
""); |
854 |
} |
854 |
} |
855 |
|
855 |
|
856 |
// null analysis -- strings concatenation |
|
|
857 |
// JLS 15.18.1: if one of the operands is null, it is replaced by "null" |
858 |
// Note: having the diagnostic could come handing when the initialization path |
859 |
// is non trivial; to get the diagnostic, simply put in place an |
860 |
// extraneous call to toString() -- and remove it before releasing. |
861 |
public void test0045_strings_concatenation() { |
862 |
this.runConformTest( |
863 |
new String[] { |
864 |
"X.java", |
865 |
"public class X {\n" + |
866 |
" String foo(String s1, String s2) {\n" + |
867 |
" if (s1 == null) { /* */ };\n" + |
868 |
" return s1 + s2;\n" + |
869 |
" }\n" + |
870 |
"}\n"}, |
871 |
""); |
872 |
} |
873 |
|
874 |
// null analysis -- strings concatenation |
875 |
public void test0046_strings_concatenation() { |
876 |
this.runConformTest( |
877 |
new String[] { |
878 |
"X.java", |
879 |
"public class X {\n" + |
880 |
" String foo(String s1, String s2) {\n" + |
881 |
" if (s1 == null) { /* */ };\n" + |
882 |
" s1 += s2;\n" + |
883 |
" return s1;\n" + |
884 |
" }\n" + |
885 |
"}\n"}, |
886 |
""); |
887 |
} |
888 |
|
889 |
// null analysis -- strings concatenation |
890 |
public void test0047_strings_concatenation() { |
891 |
this.runNegativeTest( |
892 |
new String[] { |
893 |
"X.java", |
894 |
"public class X {\n" + |
895 |
" String foo(String s1) {\n" + |
896 |
" if (s1 == null) { /* */ };\n" + |
897 |
" return s1.toString();\n" + |
898 |
" }\n" + |
899 |
"}\n"}, |
900 |
"----------\n" + |
901 |
"1. ERROR in X.java (at line 4)\n" + |
902 |
" return s1.toString();\n" + |
903 |
" ^^\n" + |
904 |
"The variable s1 may be null\n" + |
905 |
"----------\n"); |
906 |
} |
907 |
|
908 |
// null analysis -- array |
856 |
// null analysis -- array |
909 |
public void test0050_array() { |
857 |
public void test0050_array() { |
910 |
this.runConformTest( |
858 |
this.runConformTest( |
Lines 1321-1326
Link Here
|
1321 |
""); |
1269 |
""); |
1322 |
} |
1270 |
} |
1323 |
|
1271 |
|
|
|
1272 |
// null analysis -- strings concatenation |
1273 |
// JLS 15.18.1: if one of the operands is null, it is replaced by "null" |
1274 |
// Note: having the diagnostic could come handing when the initialization path |
1275 |
// is non trivial; to get the diagnostic, simply put in place an |
1276 |
// extraneous call to toString() -- and remove it before releasing. |
1277 |
public void test0120_strings_concatenation() { |
1278 |
this.runConformTest( |
1279 |
new String[] { |
1280 |
"X.java", |
1281 |
"public class X {\n" + |
1282 |
" String foo(String s1, String s2) {\n" + |
1283 |
" if (s1 == null) { /* */ };\n" + |
1284 |
" return s1 + s2;\n" + |
1285 |
" }\n" + |
1286 |
"}\n"}, |
1287 |
""); |
1288 |
} |
1289 |
|
1290 |
// null analysis -- strings concatenation |
1291 |
public void test0121_strings_concatenation() { |
1292 |
this.runConformTest( |
1293 |
new String[] { |
1294 |
"X.java", |
1295 |
"public class X {\n" + |
1296 |
" String foo(String s1, String s2) {\n" + |
1297 |
" if (s1 == null) { /* */ };\n" + |
1298 |
" s1 += s2;\n" + |
1299 |
" return s1;\n" + |
1300 |
" }\n" + |
1301 |
"}\n"}, |
1302 |
""); |
1303 |
} |
1304 |
|
1305 |
// null analysis -- strings concatenation |
1306 |
public void test0122_strings_concatenation() { |
1307 |
this.runNegativeTest( |
1308 |
new String[] { |
1309 |
"X.java", |
1310 |
"public class X {\n" + |
1311 |
" String foo(String s1) {\n" + |
1312 |
" if (s1 == null) { /* */ };\n" + |
1313 |
" return s1.toString();\n" + |
1314 |
" }\n" + |
1315 |
"}\n"}, |
1316 |
"----------\n" + |
1317 |
"1. ERROR in X.java (at line 4)\n" + |
1318 |
" return s1.toString();\n" + |
1319 |
" ^^\n" + |
1320 |
"The variable s1 may be null\n" + |
1321 |
"----------\n"); |
1322 |
} |
1323 |
|
1324 |
// null analysis -- strings concatenation |
1325 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127919 |
1326 |
// it should suffice that the return type is String to avoid |
1327 |
// errors |
1328 |
public void test0123_strings_concatenation() { |
1329 |
this.runConformTest( |
1330 |
new String[] { |
1331 |
"X.java", |
1332 |
"public class X {\n" + |
1333 |
" String foo(String s, Object o, Integer i) {\n" + |
1334 |
" if (s == null || o == null || i == null) { /* */ };\n" + |
1335 |
" if (bar()) {\n" + |
1336 |
" return s + i;\n" + // quiet: i replaced by "null" if null |
1337 |
" }\n" + |
1338 |
" return o + s;\n" + // quiet: o replaced by "null" if null |
1339 |
" }\n" + |
1340 |
" boolean bar() {\n" + |
1341 |
" return false;\n" + |
1342 |
" }\n" + |
1343 |
"}\n"}, |
1344 |
""); |
1345 |
} |
1346 |
|
1347 |
// null analysis -- strings concatenation |
1348 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127919 |
1349 |
// variant |
1350 |
public void test0124_strings_concatenation() { |
1351 |
this.runConformTest( |
1352 |
new String[] { |
1353 |
"X.java", |
1354 |
"public class X {\n" + |
1355 |
" String foo(String s, Object o, Integer i) {\n" + |
1356 |
" if (s == null || o == null || i == null) { /* */ };\n" + |
1357 |
" s += o;\n" + // quiet: o replaced by "null" if null |
1358 |
" s += i;\n" + // quiet: i replaced by "null" if null |
1359 |
" return s;\n" + |
1360 |
" }\n" + |
1361 |
"}\n"}, |
1362 |
""); |
1363 |
} |
1364 |
|
1365 |
// null analysis -- strings concatenation |
1366 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127919 |
1367 |
// variant |
1368 |
public void test0125_strings_concatenation() { |
1369 |
this.runConformTest( |
1370 |
new String[] { |
1371 |
"X.java", |
1372 |
"public class X {\n" + |
1373 |
" void foo(Object o, Integer i) {\n" + |
1374 |
" System.out.println(o + (o == null ? \"\" : o.toString()));\n" + // quiet: o replaced by "null" if null |
1375 |
" System.out.println(i + (i == null ? \"\" : i.toString()));\n" + // quiet: o replaced by "null" if null |
1376 |
" }\n" + |
1377 |
"}\n"}, |
1378 |
""); |
1379 |
} |
1380 |
|
1324 |
// null analysis -- if/else |
1381 |
// null analysis -- if/else |
1325 |
// check that obviously unreachable code does not modify the null |
1382 |
// check that obviously unreachable code does not modify the null |
1326 |
// status of a local |
1383 |
// status of a local |