java.lang.ClassCastException: scala.collection.mutable.FlatHashTable$NullSentinel$ cannot be cast to java.lang.String at $anonfun$1.apply(:9)

Scala JIRA | James Iry | 4 years ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    [SI-6908] FlatHashTable and things that depend on it like mutable.HashSet cannot store nulls - Scala

    scala-lang.org | 2 years ago
    java.lang.ClassCastException: scala.collection.mutable.FlatHashTable$NullSentinel$ cannot be cast to java.lang.String at $anonfun$1.apply(:9)
  2. 0

    mutable.HashSet or anything that depends on FlatHashTable for its implementation cannot have null values. But allowing it to support null is easy and would extend the functionality nicely scala> val h = new scala.collection.mutable.HashSet[String] h: scala.collection.mutable.HashSet[String] = Set() scala> h.contains(null) java.lang.IllegalArgumentException: Flat hash tables cannot contain null elements. at scala.collection.mutable.FlatHashTable$HashUtils$class.elemHashCode(FlatHashTable.scala:348) at scala.collection.mutable.HashSet.elemHashCode(HashSet.scala:41) at scala.collection.mutable.FlatHashTable$class.containsEntry(FlatHashTable.scala:109) at scala.collection.mutable.HashSet.containsEntry(HashSet.scala:41) at scala.collection.mutable.HashSet.contains(HashSet.scala:57) ... You might think "oh, let's just make contains smart about null" but look at this scala> val xs = null :: Nil xs: List[Null] = List(null) scala> xs.distinct java.lang.IllegalArgumentException: Flat hash tables cannot contain null elements. ...etc now, making contains not explode on null would prevent that stack trace...but the resulting set would be empty even though the original list was not. I contend that doesn't make sense and that the only thing that does make sense is to make FlatHashTable allow nulls just as List does.

    Scala JIRA | 4 years ago | James Iry
    java.lang.ClassCastException: scala.collection.mutable.FlatHashTable$NullSentinel$ cannot be cast to java.lang.String at $anonfun$1.apply(:9)
  3. 0

    Null Handling in scala.collection.mutable.FlatHashTable

    GitHub | 3 years ago | cheeseng
    java.lang.ClassCastException: scala.collection.mutable.FlatHashTable$NullSentinel$ cannot be cast to java.lang.String at $anonfun$1.apply(:9)
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ClassCastException

      scala.collection.mutable.FlatHashTable$NullSentinel$ cannot be cast to java.lang.String at $anonfun$1.apply(:9)

      at scala.collection.Iterator$class.exists()
    2. Scala
      Iterator$class.exists
      1. scala.collection.Iterator$class.exists(Iterator.scala:769)
      1 frame