Slightly deceiving error message on Collectors.toMap
Michael Nascimento
misterm at gmail.com
Wed Apr 16 22:03:15 UTC 2014
Ok, I'll file a bug when I get home. I'll do my best to prepare a patch as
well.
Regards,
Michael
On 16 Apr 2014 18:42, "Brian Goetz" <brian.goetz at oracle.com> wrote:
> 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