FULL PRODUCT VERSION :
ADDITIONAL OS VERSION INFORMATION :
64-bit Ubuntu 14.04
A DESCRIPTION OF THE PROBLEM :
The current implementation of the "hashCode" function in the convenience class "Pair" is as follows.
public int hashCode() {
// name's hashCode is multiplied by an arbitrary prime number (13)
// in order to make sure there is a difference in the hashCode between
// these two parameters:
// name: a value: aa
// name: aa value: a
return key.hashCode() * 13 + (value == null ? 0 : value.hashCode());
}
However, this is an incorrect way to compute a hash code of two values. For example, here is a trivial collision of two hash codes which should be different.
System.out.println(
new Pair<Integer,Integer>(1,0).hashCode()
==
new Pair<Integer,Integer>(0,13).hashCode()
); // => true
This can lead to hard-to-find bugs anywhere that instances of Pair are used in a data structure like a HashSet or HashTable.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javafx.util.Pair;
public class Solution {
public static void main(String args[] ) throws Exception {
System.out.println(
new Pair<Integer,Integer>(1,0).hashCode()
==
new Pair<Integer,Integer>(0,13).hashCode());
}
}
---------- END SOURCE ----------
ADDITIONAL OS VERSION INFORMATION :
64-bit Ubuntu 14.04
A DESCRIPTION OF THE PROBLEM :
The current implementation of the "hashCode" function in the convenience class "Pair" is as follows.
public int hashCode() {
// name's hashCode is multiplied by an arbitrary prime number (13)
// in order to make sure there is a difference in the hashCode between
// these two parameters:
// name: a value: aa
// name: aa value: a
return key.hashCode() * 13 + (value == null ? 0 : value.hashCode());
}
However, this is an incorrect way to compute a hash code of two values. For example, here is a trivial collision of two hash codes which should be different.
System.out.println(
new Pair<Integer,Integer>(1,0).hashCode()
==
new Pair<Integer,Integer>(0,13).hashCode()
); // => true
This can lead to hard-to-find bugs anywhere that instances of Pair are used in a data structure like a HashSet or HashTable.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javafx.util.Pair;
public class Solution {
public static void main(String args[] ) throws Exception {
System.out.println(
new Pair<Integer,Integer>(1,0).hashCode()
==
new Pair<Integer,Integer>(0,13).hashCode());
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-8144497 javafx.util.Pair null key hashcode npe
-
- Closed
-
-
JDK-8177859 Pair class throws a NullPointerException on hashCode method invocation
-
- Closed
-