Skip to content

Tuple hashCode crashes when tuple contains null #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scabug opened this issue Oct 30, 2007 · 6 comments
Closed

Tuple hashCode crashes when tuple contains null #216

scabug opened this issue Oct 30, 2007 · 6 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Oct 30, 2007

When one of the elements of a tuple is null, attempting to put the tuple in a hash map causes a !NullPointerException. It appears that the hashCode method on tuples does not handle null as a tuple element. I would expect a tuple to return some hash code even one of its elements is null.

Welcome to Scala version 2.6.0-final.
Type in expressions to have them evaluated.
Type :help for more information.

scala> val x = (null, 1)
x: (Null, Int) = (null,1)

scala> val m = new scala.collection.mutable.HashMap[(String, Int), Int]
m: scala.collection.mutable.HashMap[(String, Int),Int] = Map()

scala> m.update(x, 1)
java.lang.NullPointerException
        at scala.runtime.ScalaRunTime$$._hashCode(ScalaRunTime.scala:82)
        at scala.Tuple2.hashCode(Tuple2.scala:17)
        at scala.collection.mutable.HashTable$$class.elemHashCode(HashTable.scala:151)
        at scala.collection.mutable.HashMap.elemHashCode(HashMap.scala:33)
        at scala.collection.mutable.HashTable$$class.findEntry(HashTable.scala:66)
        at scala.collection.mutab...
scala>
@scabug
Copy link
Author

scabug commented Oct 30, 2007

Imported From: https://issues.scala-lang.org/browse/SI-216?orig=1
Reporter: Ondrej Lhotak (olhotak)
Attachments:

  • tuple.diff (created on Oct 8, 2008 7:24:05 PM UTC, 557 bytes)

@scabug
Copy link
Author

scabug commented Jun 11, 2008

pbadenski said:
Reversion: still causes an error in Scala 2.7.1 final

@scabug
Copy link
Author

scabug commented Oct 8, 2008

@paulp said:
I don't know if this is still open because there's some subtlety to the fix, but I just attached a patch that fixes this for my definition of fix.

@scabug
Copy link
Author

scabug commented Oct 28, 2008

@dragos said:
We need to check that with Martin today at the meeting. That bug was fixed, then Martin reverted that fix in a bigger commit. We'll see if that was intentional.

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone 2.7.0 deleted

@scabug
Copy link
Author

scabug commented Jan 21, 2009

@dragos said:
Fixed in r16962.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants