Slightly deceiving error message on Collectors.toMap

Brian Goetz brian.goetz at oracle.com
Wed Apr 16 21:42:27 UTC 2014


Yes, I agree that the error message is deceptive and that the approach 
you outline is about the best we can easily do.

On 4/16/2014 4: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
>
> 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