Lines 44-50
Link Here
|
44 |
// Only the highest compliance level is run; add the VM argument |
44 |
// Only the highest compliance level is run; add the VM argument |
45 |
// -Dcompliance=1.4 (for example) to lower it if needed |
45 |
// -Dcompliance=1.4 (for example) to lower it if needed |
46 |
static { |
46 |
static { |
47 |
// TESTS_NAMES = new String[] { "testBug336428e" }; |
47 |
// TESTS_NAMES = new String[] { "testBug339250" }; |
48 |
// TESTS_NUMBERS = new int[] { 561 }; |
48 |
// TESTS_NUMBERS = new int[] { 561 }; |
49 |
// TESTS_RANGE = new int[] { 1, 2049 }; |
49 |
// TESTS_RANGE = new int[] { 1, 2049 }; |
50 |
} |
50 |
} |
Lines 14441-14444
Link Here
|
14441 |
" 17 return\n"; |
14441 |
" 17 return\n"; |
14442 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
14442 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); |
14443 |
} |
14443 |
} |
|
|
14444 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=339250 |
14445 |
// Check code gen |
14446 |
public void testBug339250() throws Exception { |
14447 |
Map options = getCompilerOptions(); |
14448 |
options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); |
14449 |
this.runConformTest( |
14450 |
new String[] { |
14451 |
"X.java", |
14452 |
"public class X {\n" + |
14453 |
" public static void main(String[] args) {\n" + |
14454 |
" String s = null;\n" + |
14455 |
" s += \"correctly\";\n" + |
14456 |
" if (s != null) {\n" + // s cannot be null |
14457 |
" System.out.println(\"It works \" + s);\n" + |
14458 |
" }\n" + |
14459 |
" }\n" + |
14460 |
"}", |
14461 |
}, |
14462 |
"It works nullcorrectly", |
14463 |
null, |
14464 |
true, |
14465 |
null, |
14466 |
options, |
14467 |
null); |
14468 |
} |
14469 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=339250 |
14470 |
// Check that the redundant null check warning is correctly produced |
14471 |
public void testBug339250a() throws Exception { |
14472 |
this.runNegativeTest( |
14473 |
new String[] { |
14474 |
"X.java", |
14475 |
"public class X {\n" + |
14476 |
" public static void main(String[] args) {\n" + |
14477 |
" String s = null;\n" + |
14478 |
" s += \"correctly\";\n" + |
14479 |
" if (s != null) {\n" + // s cannot be null |
14480 |
" System.out.println(\"It works \" + s);\n" + |
14481 |
" }\n" + |
14482 |
" }\n" + |
14483 |
"}", |
14484 |
}, |
14485 |
"----------\n" + |
14486 |
"1. ERROR in X.java (at line 5)\n" + |
14487 |
" if (s != null) {\n" + |
14488 |
" ^\n" + |
14489 |
"Redundant null check: The variable s cannot be null at this location\n" + |
14490 |
"----------\n"); |
14491 |
} |
14492 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=339250 |
14493 |
// Check that the redundant null check warning is correctly produced |
14494 |
public void testBug339250b() throws Exception { |
14495 |
this.runNegativeTest( |
14496 |
new String[] { |
14497 |
"X.java", |
14498 |
"public class X {\n" + |
14499 |
" public static void main(String[] args) {\n" + |
14500 |
" String s = null;\n" + |
14501 |
" s += null;\n" + |
14502 |
" if (s != null) {\n" + // s is definitely not null |
14503 |
" System.out.println(\"It works \" + s);\n" + |
14504 |
" }\n" + |
14505 |
" s = null;\n" + |
14506 |
" if (s != null) {\n" + // s is definitely null |
14507 |
" System.out.println(\"Fails \" + s);\n" + |
14508 |
" } else {\n" + |
14509 |
" System.out.println(\"Works second time too \" + s);\n" + |
14510 |
" }\n" + |
14511 |
" }\n" + |
14512 |
"}", |
14513 |
}, |
14514 |
"----------\n" + |
14515 |
"1. ERROR in X.java (at line 5)\n" + |
14516 |
" if (s != null) {\n" + |
14517 |
" ^\n" + |
14518 |
"Redundant null check: The variable s cannot be null at this location\n" + |
14519 |
"----------\n" + |
14520 |
"2. ERROR in X.java (at line 9)\n" + |
14521 |
" if (s != null) {\n" + |
14522 |
" ^\n" + |
14523 |
"Null comparison always yields false: The variable s can only be null at this location\n" + |
14524 |
"----------\n" + |
14525 |
"3. WARNING in X.java (at line 9)\n" + |
14526 |
" if (s != null) {\n" + |
14527 |
" System.out.println(\"Fails \" + s);\n" + |
14528 |
" } else {\n" + |
14529 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
14530 |
"Dead code\n" + |
14531 |
"----------\n"); |
14532 |
} |
14444 |
} |
14533 |
} |