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

HashMap spliterator tryAdvance() encounters remaining elements after forEachRemaining()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8
    • 8
    • core-libs
    • None

    Description

      The spliterator added to HashMap will often (but not always) encounter a remaining element during a tryAdvance() call after forEachRemaining() has been called. (My guess is that the unpredictability is due to HashMap's random hashing seed).

      See the attached test case. It's loosely based on the testMixedTryAdvanceForEach() test from SpliteratorTraversingAndSplittingTest.java. Running it a few times should eventually produce output similar to:

      ...
      forEachRemaining: String158
      forEachRemaining: String650
      forEachRemaining: String29
      forEachRemaining: String309
      forEachRemaining: String715
      Exception in thread "main" java.lang.Error: tryAdvance should have no elements: String51
      at ObjSplitter.fail(ObjSplitter.java:35)
      at ObjSplitter.lambda$3(ObjSplitter.java:31)
      at ObjSplitter$$Lambda$4.accept(Unknown Source)
      at java.util.HashMap$KeySpliterator.tryAdvance(HashMap.java:1528)
      at ObjSplitter.main(ObjSplitter.java:31)

      Attachments

        Issue Links

          Activity

            People

              psandoz Paul Sandoz
              bchristi Brent Christian
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: