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

ClassCastException when adding a Long and a Double to the same ConcurrentSkipListSet

    Details

      Description

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

      ADDITIONAL OS VERSION INFORMATION :
      Linux pr0methean-betterrandom-5379202 4.9.17-c9 #1 SMP Thu Mar 23 01:38:54 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Reproduced in multiple Linux and OSX environments.

      A DESCRIPTION OF THE PROBLEM :
      A ClassCastException occurs when adding a Long and a Double to the same ConcurrentSkipListSet (and presumably also when adding them as keys to the same ConcurrentSkipListMap).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Add a Long and a Double to the same ConcurrentSkipListSet<? super Number> (see source code below).


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The program runs and exits without crashing.
      ACTUAL -
      The program crashes with a ClassCastException (see stack trace below).

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Double
      at java.lang.Double.compareTo(Double.java:49)
      at java.util.concurrent.ConcurrentSkipListMap.cpr(ConcurrentSkipListMap.java:655)
      at java.util.concurrent.ConcurrentSkipListMap.doPut(ConcurrentSkipListMap.java:835)
      at java.util.concurrent.ConcurrentSkipListMap.putIfAbsent(ConcurrentSkipListMap.java:1962)
      at java.util.concurrent.ConcurrentSkipListSet.add(ConcurrentSkipListSet.java:241)
      at Main.main(Main.java:7)
      exited with non-zero status
       

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.concurrent.ConcurrentSkipListSet;

      public class Main {
        public static void main(String[] args) {
          ConcurrentSkipListSet<Number> set = new ConcurrentSkipListSet<>();
          set.add(1L);
          set.add(2.5); // ClassCastException here!
        }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              psonal Pallavi Sonal
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: