Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8040892

Incorrect message in Exception thrown by Collectors.toMap(Function,Function)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:

      Description

      For this very short test case:

      Stream.of(3, 5).collect(toMap(i -> i % 2, Integer::reverse));

      The following exception is produced:

      Exception in thread "main" java.lang.IllegalStateException: Duplicate key -1073741824
      at java.util.stream.Collectors.lambda$throwingMerger$90(Collectors.java:133)

      Clearly, the value being printed is not the key, but rather one of two values for which there is a key collision.

      The message thrown should either display at least two values for which there is a key collision or ideally the key for which the collision happened.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              plevart Peter Levart
              Reporter:
              misterm Michael Santos
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: