Skip to content

Commit 243787e

Browse files
Regression test for #3319 (#3391)
This was fixed by #3382
1 parent c003779 commit 243787e

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTests21.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,4 +1280,87 @@ void goo() {
12801280
""";
12811281
runner.runNegativeTest();
12821282
}
1283+
1284+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3319
1285+
// [Enhanced Switch][Null] Inconsistent nullness propagation
1286+
public void testIssue3319() {
1287+
Runner runner = getDefaultRunner();
1288+
runner.testFiles = new String[] {
1289+
"X.java",
1290+
"""
1291+
import org.eclipse.jdt.annotation.NonNull;
1292+
1293+
public class X {
1294+
static @NonNull Object foo(Object o) {
1295+
switch (o) {
1296+
case String s -> {
1297+
if (o == null) {
1298+
System.out.println("o cannot be null at all!");
1299+
}
1300+
System.out.println();
1301+
}
1302+
default -> {
1303+
if (o == null) {
1304+
System.out.println("o cannot be null at all!");
1305+
}
1306+
System.out.println();
1307+
}
1308+
}
1309+
return new Object();
1310+
}
1311+
1312+
static @NonNull Object foo(X o) {
1313+
switch (o) {
1314+
case X s -> {
1315+
if (o == null) {
1316+
System.out.println("o cannot be null at all!");
1317+
}
1318+
System.out.println(s);
1319+
}
1320+
}
1321+
return new Object();
1322+
}
1323+
}
1324+
"""
1325+
};
1326+
runner.expectedCompilerLog =
1327+
"----------\n" +
1328+
"1. ERROR in X.java (at line 7)\n" +
1329+
" if (o == null) {\n" +
1330+
" ^\n" +
1331+
"Null comparison always yields false: The variable o cannot be null at this location\n" +
1332+
"----------\n" +
1333+
"2. WARNING in X.java (at line 7)\n" +
1334+
" if (o == null) {\n" +
1335+
" System.out.println(\"o cannot be null at all!\");\n" +
1336+
" }\n" +
1337+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
1338+
"Dead code\n" +
1339+
"----------\n" +
1340+
"3. ERROR in X.java (at line 13)\n" +
1341+
" if (o == null) {\n" +
1342+
" ^\n" +
1343+
"Null comparison always yields false: The variable o cannot be null at this location\n" +
1344+
"----------\n" +
1345+
"4. WARNING in X.java (at line 13)\n" +
1346+
" if (o == null) {\n" +
1347+
" System.out.println(\"o cannot be null at all!\");\n" +
1348+
" }\n" +
1349+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
1350+
"Dead code\n" +
1351+
"----------\n" +
1352+
"5. ERROR in X.java (at line 25)\n" +
1353+
" if (o == null) {\n" +
1354+
" ^\n" +
1355+
"Null comparison always yields false: The variable o cannot be null at this location\n" +
1356+
"----------\n" +
1357+
"6. WARNING in X.java (at line 25)\n" +
1358+
" if (o == null) {\n" +
1359+
" System.out.println(\"o cannot be null at all!\");\n" +
1360+
" }\n" +
1361+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
1362+
"Dead code\n" +
1363+
"----------\n";
1364+
runner.runNegativeTest();
1365+
}
12831366
}

0 commit comments

Comments
 (0)