-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8u121
-
generic
-
generic
FULL PRODUCT VERSION :
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
javafx.util.Pair<String, String> class throws a NullPointerException on hashCode () method invocation.
It happens when key is null.
This is my test code:
package zu.luciano;
import javafx.util.Pair;
public class PairTest {
public static void main(String[] args) {
Pair<String, String> p = new Pair<String, String>(null, "v");
p.hashCode();
}
}
The bug is on row 97 of Pair class:
return key.hashCode() * 13 + (value == null ? 0 : value.hashCode());
Suggested fix is:
return (key == null ? 0 : key.hashCode()) * 13 + (value == null ? 0 : value.hashCode());
OR if key == null is not a permitted value add a condition in constructor method.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run this code:
package zu.luciano;
import javafx.util.Pair;
public class PairTest {
public static void main(String[] args) {
Pair<String, String> p = new Pair<String, String>(null, "v");
p.hashCode();
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
an integer as hashcode
ACTUAL -
NullPointerException
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package zu.luciano;
import javafx.util.Pair;
public class PairTest {
public static void main(String[] args) {
Pair<String, String> p = new Pair<String, String>(null, "v");
p.hashCode();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Check if key is null, of course.
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
javafx.util.Pair<String, String> class throws a NullPointerException on hashCode () method invocation.
It happens when key is null.
This is my test code:
package zu.luciano;
import javafx.util.Pair;
public class PairTest {
public static void main(String[] args) {
Pair<String, String> p = new Pair<String, String>(null, "v");
p.hashCode();
}
}
The bug is on row 97 of Pair class:
return key.hashCode() * 13 + (value == null ? 0 : value.hashCode());
Suggested fix is:
return (key == null ? 0 : key.hashCode()) * 13 + (value == null ? 0 : value.hashCode());
OR if key == null is not a permitted value add a condition in constructor method.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run this code:
package zu.luciano;
import javafx.util.Pair;
public class PairTest {
public static void main(String[] args) {
Pair<String, String> p = new Pair<String, String>(null, "v");
p.hashCode();
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
an integer as hashcode
ACTUAL -
NullPointerException
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package zu.luciano;
import javafx.util.Pair;
public class PairTest {
public static void main(String[] args) {
Pair<String, String> p = new Pair<String, String>(null, "v");
p.hashCode();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Check if key is null, of course.
- duplicates
-
JDK-8140503 Improve javafx.util.Pair hash code computation
-
- Resolved
-