diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/NewCollectionAliasing.java b/java/java-tests/testData/inspection/dataFlow/fixture/NewCollectionAliasing.java new file mode 100644 index 000000000000..8635e508c3d9 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/NewCollectionAliasing.java @@ -0,0 +1,20 @@ +// IDEA-299423 +import java.util.*; + +class Test { + private static void exampleThree() { + final Queue queue1 = new ArrayDeque<>(List.of("foo1", "bar1")); + final Queue queue2 = new ArrayDeque<>(List.of("foo2", "bar2")); + final Queue queue3 = new ArrayDeque<>(List.of("foo3", "bar3")); + + if(!queue1.isEmpty() && !queue2.isEmpty() && !queue3.isEmpty()) { + final String poll1 = queue1.poll(); + final String poll2 = queue2.poll(); + final String poll3 = queue3.poll(); + // NPE warning for poll2.getBytes() and poll3.getBytes() because poll2 and poll3 might be null + if (poll1.getBytes().length == poll2.getBytes().length || poll3.getBytes().length != 0) { + // ... + } + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection9Test.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection9Test.java index 509ffb5965af..b2c79508b78a 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection9Test.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection9Test.java @@ -21,4 +21,5 @@ public class DataFlowInspection9Test extends DataFlowInspectionTestCase { public void testMutabilityJdk9() { doTest();} public void testMutabilityInferred() { doTest(); } public void testObjectsRequireNonNullElse() { doTest(); } + public void testNewCollectionAliasing() { doTest(); } } \ No newline at end of file diff --git a/java/jdkAnnotations/java/util/annotations.xml b/java/jdkAnnotations/java/util/annotations.xml index f2a1a11e38a8..549bf6507d34 100644 --- a/java/jdkAnnotations/java/util/annotations.xml +++ b/java/jdkAnnotations/java/util/annotations.xml @@ -30,6 +30,21 @@ + + + + + + + + + + + + + + + @@ -72,12 +87,27 @@ + + + + + + + + + + + + + + + @@ -2945,30 +2975,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -3878,6 +3948,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -3885,6 +3985,16 @@ + + + + + + + + + +