Skip to content

immutable.HashMap.size() can be induced to return -1 #768

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 Apr 17, 2008 · 8 comments
Closed

immutable.HashMap.size() can be induced to return -1 #768

scabug opened this issue Apr 17, 2008 · 8 comments
Milestone

Comments

@scabug
Copy link

scabug commented Apr 17, 2008

I'm using 2.7.1-RC1. this code:

val m = new collection.immutable.HashMap[Int,Int]
println(m.size)
m(1) = 1
println(m.size)

prints:

0
-1

shouldn't the -1 be 0?

@scabug
Copy link
Author

scabug commented Apr 17, 2008

Imported From: https://issues.scala-lang.org/browse/SI-768?orig=1
Reporter: @SethTisue

@scabug
Copy link
Author

scabug commented Apr 18, 2008

@odersky said:
fixed in r14704

@scabug
Copy link
Author

scabug commented Apr 18, 2008

@ijuma said:
It seems like the same bug affects immutable.HashSet too:

    val m = new collection.immutable.HashSet[Int]
    println(m.size)
    m + 1
    println(m.size)

prints exactly the same as the report here. The fix only seems to fix HashMap.

@scabug
Copy link
Author

scabug commented Apr 18, 2008

@odersky said:
Thanks for having spotted this. It's fixed now in HashSet as well.

@scabug
Copy link
Author

scabug commented Apr 18, 2008

@ijuma said:
Thanks. :)

@scabug
Copy link
Author

scabug commented Apr 19, 2008

@ijuma said:
I was curious if the immutable.HashSet part of the fix would have any effect on ticket #454. While testing it, it seems like #454 is the same as this but the immutable.HashSet fix is incorrect. It does:

s += tableSize 

instead of

s += m.tableSize 

So, once you fix the "fix", feel free to close #454 too. :)

@scabug
Copy link
Author

scabug commented Apr 21, 2008

@ijuma said:
Just for reference, this is now completely fixed in r14727.

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone next_bugfix deleted

@scabug scabug closed this as completed May 18, 2011
@scabug scabug added this to the 2.7.1 milestone Apr 6, 2017
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

1 participant