You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is something we've stumbled over internally. The contract for ImmutableSet.of() allows duplicates on the other hand, which is what devs normally expect.
What did you want to happen?
I think the idea behind Set.of() to throw is to catch errors where users may have unintentionally specified duplicates. For instance it seems reasonable to throw if say you've accidentally written something like this:
It seems desirable to let this kind of usage ^ continue but in cases where the Set elements are not compile time constants it probably makes sense to warn and instead recommend ImmutableSet.of().
This is a low priority issue though as whenever it happens its really quick to diagnose and fix.
The text was updated successfully, but these errors were encountered:
What happened?
The
Set.of()
factory methods are a bit dangerous to use. If there are duplicate elements it will throw at runtime, for example:This is something we've stumbled over internally. The contract for
ImmutableSet.of()
allows duplicates on the other hand, which is what devs normally expect.What did you want to happen?
I think the idea behind
Set.of()
to throw is to catch errors where users may have unintentionally specified duplicates. For instance it seems reasonable to throw if say you've accidentally written something like this:It seems desirable to let this kind of usage ^ continue but in cases where the
Set
elements are not compile time constants it probably makes sense to warn and instead recommendImmutableSet.of()
.This is a low priority issue though as whenever it happens its really quick to diagnose and fix.
The text was updated successfully, but these errors were encountered: