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

ClassCastException HashMap.java:1819

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 8u40
    • core-libs

      FULL PRODUCT VERSION :
      java version "1.8.0_40"
      Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
      Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      inux xxx 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u2 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Under certain circumstances, new values cannot be put to a HashMap due to a ClassCastException. This apparently happens when the magical binsize is reached and the map internally should convert to trees (treeify). Here is the cast trace:

      Caused by: java.lang.ClassCastException: java.util.HashMap$Node cannot be cast to java.util.HashMap$TreeNode
              at java.util.HashMap$TreeNode.moveRootToFront(HashMap.java:1819) ~[?:1.8.0_40]
              at java.util.HashMap$TreeNode.treeify(HashMap.java:1936) ~[?:1.8.0_40]
              at java.util.HashMap.treeifyBin(HashMap.java:771) ~[?:1.8.0_40]
              at java.util.HashMap.putVal(HashMap.java:643) ~[?:1.8.0_40]
              at java.util.HashMap.put(HashMap.java:611) ~[?:1.8.0_40]

      Indeed, if you look to the code that the Node<K,V>[] tab cannot contain elements that could be cast to TreeNode.

      REGRESSION. Last worked in version 6u45

      ADDITIONAL REGRESSION INFORMATION:
      A quick look to the code will reveal this issue.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just put values to a hashmap.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      That this code is fixed.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Caused by: java.lang.ClassCastException: java.util.HashMap$Node cannot be cast to java.util.HashMap$TreeNode
              at java.util.HashMap$TreeNode.moveRootToFront(HashMap.java:1819) ~[?:1.8.0_40]
              at java.util.HashMap$TreeNode.treeify(HashMap.java:1936) ~[?:1.8.0_40]
              at java.util.HashMap.treeifyBin(HashMap.java:771) ~[?:1.8.0_40]
              at java.util.HashMap.putVal(HashMap.java:643) ~[?:1.8.0_40]
              at java.util.HashMap.put(HashMap.java:611) ~[?:1.8.0_40]

      REPRODUCIBILITY :
      This bug can be reproduced often.

      CUSTOMER SUBMITTED WORKAROUND :
      In this specific case we use a TreeMap as a workaround.

            pardesha Pardeep Sharma
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: