You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
The text was updated successfully, but these errors were encountered:
"It's pretty sad that there is this protected method "removeElem" which insists on allocating a Some and returning the removed element in it - which is then NEVER USED ANYWHERE. The only uses to which the return value are put are "isDefined" and tossing it aside. Given that object FlatHashTable is private[collection], it's pretty unlikely it does that for the benefit of code which is not in trunk."
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.
The text was updated successfully, but these errors were encountered: