Slightly deceiving error message on Collectors.toMap
Peter Levart
peter.levart at gmail.com
Thu Apr 17 15:50:49 UTC 2014
On 04/16/2014 10:18 PM, Michael Nascimento wrote:
> Hi folks,
>
> For this very short test case:
>
> Stream.of(1, 1).collect(toMap(identity(), Integer::reverse));
>
> The following exception is produced:
>
> java.lang.IllegalStateException: Duplicate key -2147483648
> at java.util.stream.Collectors.lambda$throwingMerger$90(Collectors.java:133)
>
> Obviously, the value being printed is not a key, but a value of the
> map. Since capturing the actual key does not seem possible, I suggest
> changing this message to something like:
>
> Duplicate values for a key %s %s
That's confusing too. It's not a problem with duplicate values but with
duplicate keys. Maybe:
Duplicate key, mapped to value %s
Regards, Peter
>
> And include both of them in the error message.
>
> Should I file a bug for this?
>
> Regards,
> Michael
>
More information about the lambda-dev
mailing list