|
Lines 5425-5430
Link Here
|
| 5425 |
"Null type mismatch (type annotations): required \'@NonNull Collection\' but this expression has type \'@Nullable Collection\'\n" + |
5425 |
"Null type mismatch (type annotations): required \'@NonNull Collection\' but this expression has type \'@Nullable Collection\'\n" + |
| 5426 |
"----------\n"); |
5426 |
"----------\n"); |
| 5427 |
} |
5427 |
} |
|
|
5428 |
// top-level annotation is overridden at use-site, details remain - parameterized type |
| 5429 |
public void testTypeVariable19() { |
| 5430 |
runNegativeTestWithLibs( |
| 5431 |
new String[] { |
| 5432 |
"X.java", |
| 5433 |
"import java.util.ArrayList;\n" + |
| 5434 |
"import java.util.List;\n" + |
| 5435 |
"\n" + |
| 5436 |
"import org.eclipse.jdt.annotation.NonNull;\n" + |
| 5437 |
"import org.eclipse.jdt.annotation.Nullable;\n" + |
| 5438 |
"interface I<T,U extends List<T>> {\n" + |
| 5439 |
" U get0();\n" + |
| 5440 |
" @Nullable U get1();\n" + |
| 5441 |
" @NonNull U get2();\n" + |
| 5442 |
"}\n" + |
| 5443 |
"class X {\n" + |
| 5444 |
" static String test (I<@Nullable String, @NonNull ArrayList<@Nullable String>> i1,\n" + |
| 5445 |
" I<@NonNull String, @Nullable ArrayList<@NonNull String>> i2, int s) {\n" + |
| 5446 |
" switch(s) {\n" + |
| 5447 |
" case 0 : return i1.get0().get(0).toUpperCase(); // problem at detail\n" + |
| 5448 |
" case 1 : return i1.get1().get(0).toUpperCase(); // 2 problems\n" + |
| 5449 |
" case 2 : return i1.get2().get(0).toUpperCase(); // problem at detail\n" + |
| 5450 |
" case 3 : return i2.get0().get(0).toUpperCase(); // problem at top\n" + |
| 5451 |
" case 4 : return i2.get1().get(0).toUpperCase(); // problem at top\n" + |
| 5452 |
" case 5 : return i2.get2().get(0).toUpperCase(); // OK\n" + |
| 5453 |
" default : return \"\";" + |
| 5454 |
" }\n" + |
| 5455 |
" }\n" + |
| 5456 |
"}\n" |
| 5457 |
}, |
| 5458 |
getCompilerOptions(), |
| 5459 |
"----------\n" + |
| 5460 |
"1. ERROR in X.java (at line 15)\n" + |
| 5461 |
" case 0 : return i1.get0().get(0).toUpperCase(); // problem at detail\n" + |
| 5462 |
" ^^^^^^^^^^^^^^^^\n" + |
| 5463 |
"Potential null pointer access: The method get(int) may return null\n" + |
| 5464 |
"----------\n" + |
| 5465 |
"2. ERROR in X.java (at line 16)\n" + |
| 5466 |
" case 1 : return i1.get1().get(0).toUpperCase(); // 2 problems\n" + |
| 5467 |
" ^^^^^^^^^\n" + |
| 5468 |
"Potential null pointer access: The method get1() may return null\n" + |
| 5469 |
"----------\n" + |
| 5470 |
"3. ERROR in X.java (at line 16)\n" + |
| 5471 |
" case 1 : return i1.get1().get(0).toUpperCase(); // 2 problems\n" + |
| 5472 |
" ^^^^^^^^^^^^^^^^\n" + |
| 5473 |
"Potential null pointer access: The method get(int) may return null\n" + |
| 5474 |
"----------\n" + |
| 5475 |
"4. ERROR in X.java (at line 17)\n" + |
| 5476 |
" case 2 : return i1.get2().get(0).toUpperCase(); // problem at detail\n" + |
| 5477 |
" ^^^^^^^^^^^^^^^^\n" + |
| 5478 |
"Potential null pointer access: The method get(int) may return null\n" + |
| 5479 |
"----------\n" + |
| 5480 |
"5. ERROR in X.java (at line 18)\n" + |
| 5481 |
" case 3 : return i2.get0().get(0).toUpperCase(); // problem at top\n" + |
| 5482 |
" ^^^^^^^^^\n" + |
| 5483 |
"Potential null pointer access: The method get0() may return null\n" + |
| 5484 |
"----------\n" + |
| 5485 |
"6. ERROR in X.java (at line 19)\n" + |
| 5486 |
" case 4 : return i2.get1().get(0).toUpperCase(); // problem at top\n" + |
| 5487 |
" ^^^^^^^^^\n" + |
| 5488 |
"Potential null pointer access: The method get1() may return null\n" + |
| 5489 |
"----------\n"); |
| 5490 |
} |
| 5491 |
// top-level annotation is overridden at use-site, array with anotations on dimensions |
| 5492 |
public void testTypeVariable19a() { |
| 5493 |
runNegativeTestWithLibs( |
| 5494 |
new String[] { |
| 5495 |
"X.java", |
| 5496 |
"import org.eclipse.jdt.annotation.NonNull;\n" + |
| 5497 |
"import org.eclipse.jdt.annotation.Nullable;\n" + |
| 5498 |
"interface I1<T> {\n" + |
| 5499 |
" T @Nullable[] get0();\n" + |
| 5500 |
" @Nullable T @NonNull[] get1();\n" + |
| 5501 |
" @Nullable T @Nullable[] get2();\n" + |
| 5502 |
"}\n" + |
| 5503 |
"interface I2<T> {\n" + |
| 5504 |
" T @NonNull[] get0();\n" + |
| 5505 |
" @NonNull T @NonNull[] get1();\n" + |
| 5506 |
" @NonNull T @Nullable[] get2();\n" + |
| 5507 |
"}\n" + |
| 5508 |
"class X {\n" + |
| 5509 |
" static String test (I1<@NonNull String> i1, I2<@Nullable String> i2, int s) {\n" + |
| 5510 |
" switch (s) {\n" + |
| 5511 |
" case 0: return i1.get0()[0].toUpperCase(); // problem on array\n" + |
| 5512 |
" case 1: return i1.get1()[0].toUpperCase(); // problem on element\n" + |
| 5513 |
" case 2: return i1.get2()[0].toUpperCase(); // 2 problems\n" + |
| 5514 |
" case 3: return i2.get0()[0].toUpperCase(); // problem on element\n" + |
| 5515 |
" case 4: return i2.get1()[0].toUpperCase(); // OK\n" + |
| 5516 |
" case 5: return i2.get2()[0].toUpperCase(); // problem on array\n" + |
| 5517 |
" default: return \"\";\n" + |
| 5518 |
" }\n" + |
| 5519 |
" }\n" + |
| 5520 |
"}\n" |
| 5521 |
}, |
| 5522 |
getCompilerOptions(), |
| 5523 |
"----------\n" + |
| 5524 |
"1. ERROR in X.java (at line 16)\n" + |
| 5525 |
" case 0: return i1.get0()[0].toUpperCase(); // problem on array\n" + |
| 5526 |
" ^^^^^^^^^\n" + |
| 5527 |
"Potential null pointer access: The method get0() may return null\n" + |
| 5528 |
"----------\n" + |
| 5529 |
"2. ERROR in X.java (at line 17)\n" + |
| 5530 |
" case 1: return i1.get1()[0].toUpperCase(); // problem on element\n" + |
| 5531 |
" ^^^^^^^^^^^^\n" + |
| 5532 |
"Potential null pointer access: array element may be null\n" + |
| 5533 |
"----------\n" + |
| 5534 |
"3. ERROR in X.java (at line 18)\n" + |
| 5535 |
" case 2: return i1.get2()[0].toUpperCase(); // 2 problems\n" + |
| 5536 |
" ^^^^^^^^^\n" + |
| 5537 |
"Potential null pointer access: The method get2() may return null\n" + |
| 5538 |
"----------\n" + |
| 5539 |
"4. ERROR in X.java (at line 18)\n" + |
| 5540 |
" case 2: return i1.get2()[0].toUpperCase(); // 2 problems\n" + |
| 5541 |
" ^^^^^^^^^^^^\n" + |
| 5542 |
"Potential null pointer access: array element may be null\n" + |
| 5543 |
"----------\n" + |
| 5544 |
"5. ERROR in X.java (at line 19)\n" + |
| 5545 |
" case 3: return i2.get0()[0].toUpperCase(); // problem on element\n" + |
| 5546 |
" ^^^^^^^^^^^^\n" + |
| 5547 |
"Potential null pointer access: array element may be null\n" + |
| 5548 |
"----------\n" + |
| 5549 |
"6. ERROR in X.java (at line 21)\n" + |
| 5550 |
" case 5: return i2.get2()[0].toUpperCase(); // problem on array\n" + |
| 5551 |
" ^^^^^^^^^\n" + |
| 5552 |
"Potential null pointer access: The method get2() may return null\n" + |
| 5553 |
"----------\n"); |
| 5554 |
} |
| 5428 |
public void testBug434600() { |
5555 |
public void testBug434600() { |
| 5429 |
runConformTestWithLibs( |
5556 |
runConformTestWithLibs( |
| 5430 |
new String[] { |
5557 |
new String[] { |