From 02a063f866a245662896589c35875f61d3303e45 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Fri, 26 Sep 2025 18:03:07 +0200 Subject: [PATCH] [java-dfa] Test for IDEA-375523 False positive "Argument might be null" with Guava Streams GitOrigin-RevId: b6569cf1c45c5de3486d823f37a1426f81d0382d --- .../fixture/GenericVarargNullability.java | 44 +++++++++++++++++++ .../DataFlowInspection21Test.java | 4 ++ 2 files changed, 48 insertions(+) create mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/GenericVarargNullability.java diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/GenericVarargNullability.java b/java/java-tests/testData/inspection/dataFlow/fixture/GenericVarargNullability.java new file mode 100644 index 000000000000..a15259e92a0c --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/GenericVarargNullability.java @@ -0,0 +1,44 @@ +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.NotNullByDefault; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.stream.Stream; + +abstract class StreamsNull { + @NotNullByDefault + static class Streams { + @SafeVarargs + static native Stream concat(Stream... streams); + } + + List calc(Stream positions, Stream leg1, Stream leg2, double v) { + return Streams.concat( + positions.map(Leg::getInstrument), + leg1.map(Leg::getInstrument), + leg2.map(Leg::getInstrument) + ) + .filter(i -> isInteresting(i, v)) + .toList(); + } + + List calc2(Stream positions, Stream leg1, Stream leg2, double v) { + return Streams.concat( + positions.map(Leg::getInstrument), + leg1.map(Leg::getInstrument2), + leg2.map(Leg::getInstrument) + ) + .filter(i -> isInteresting(i, v)) + .toList(); + } + + protected abstract boolean isInteresting(@NotNull String instrument, + double v); +} + +interface Leg { + @NotNull + String getInstrument(); + @Nullable + String getInstrument2(); +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection21Test.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection21Test.java index e65611bfa14a..07f9fc252699 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection21Test.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection21Test.java @@ -215,6 +215,10 @@ public class DataFlowInspection21Test extends DataFlowInspectionTestCase { public void testGuavaIterablesProblems() { doTest(); } + + public void testGenericVarargNullability() { + doTest(); + } public void testPassthroughGenericParameter() { doTestWith((dfi, cvi) -> dfi.TREAT_UNKNOWN_MEMBERS_AS_NULLABLE = true);