Problem
IntelliJ IDEA 2025.3 reports a false nullability warning when calling ContainerUtil.map2SetNotNull() with a lambda that returns null.
The inspection incorrectly requires the lambda return type to be non-null, even though map2SetNotNull is designed to filter out null values.
Example:
Set<@NotNull VirtualFile> files = ContainerUtil.map2SetNotNull(
usages, usage -> usage instanceof UsageInFile ? ((UsageInFile)usage).getFile() : null);
The null return in the lambda is flagged as a nullability violation.
Cause
The type variable V in map2SetNotNull is inferred as @NotNull VirtualFile from the result set type. The mapper parameter was declared as @NotNull Function<? super T, ? extends V>, which propagated the non-null annotation to the lambda return type.
This behavior is consistent with Kotlin nullability inference — the equivalent Kotlin declaration also requires V? as the mapper return type.
Resolution
The method signature has been updated to @NotNull Function<? super T, ? extends @Nullable V>, allowing the lambda to return null as intended.
Fixed in IntelliJ IDEA builds: 253.3048, 253.29346.329.
See Lambda return type is required to be not-null for map2SetNotNull method for details.
Comments
0 comments
Please sign in to leave a comment.