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);