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

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 9
    • 8
    • core-libs

    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

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

              Dates

                Created:
                Updated:
                Resolved: