Solution of rule java:S4738 can easily lead to NPE

The solution of rule java:S4738 can easily lead to NPEs:

System.err.println(ImmutableSet.of(42L).contains(null)); // => false
System.err.println(Set.of(42L).contains(null)); // => NPE

Here SQ recommends replacing guavas ImmutableSet.of with Set.of:

if (ImmutableSet.of(1L, 2L).contains(someRecord.getSomeValue()))
{
    return Optional.empty();
}

Since someRecord.getSomeValue() could be null this would lead to a NPE!

The solution List.of (and probably more) also could lead to a NPE.

Hey @blue42,

Thank you for reporting this issue. I think what you shared makes a lot of sense and we cannot asumme that substituting one type of collection with another will work all of the time.

I created this ticket to refine the behavior of S4738. But beware this task is big one that covers cases that go beyond the ones you shared so it might take a little while before we address it.

Still, let me know if you can think of other cases, I will be happy to update the ticket.

Cheers,

Dorian