-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
7
-
x86
-
windows_xp
FULL PRODUCT VERSION :
JDK 1.7 Version
=============
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b22)
Java HotSpot(TM) Client VM (build 23.0-b21, mixed mode, sharing)
JDK 1.6 version
=============
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
System: Microsoft XP Professional version 2002 Service Pack 3
Version: 5.1.2600 Service Pack 3 Build 2600
A DESCRIPTION OF THE PROBLEM :
The hash code value is not stable in JDK 1.7, but t is same in JDK 1.6 if you run multiple time.
REGRESSION. Last worked in version 6u31
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Source code is attached. Kindly run the source code for the JDK version mentioned.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The hash code value is not stable in JDK 1.7
ACTUAL -
JDK 1.7
=======
G:\javapgms>java TestEnum
hashCode get: 18426253
hashCode instance: 77
G:\javapgms>java TestEnum
hashCode get: 3195425
hashCode instance: 77
G:\javapgms>java TestEnum
hashCode get: 3195425
hashCode instance: 77
JDK 1.6
======
G:\javapgms>java TestEnum
hashCode get: 11394033
hashCode instance: 77
G:\javapgms>java TestEnum
hashCode get: 11394033
hashCode instance: 77
G:\javapgms>java TestEnum
hashCode get: 11394033
hashCode instance: 77
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
The below program were tried in JDK 1.6 and JDK1.7
The hash code value is not stable in JDK 1.7, but it is same in JDK 1.6
class TestEnum {
enum Gender {
M("Male"), F("Female");
private String description;
Gender(String description){
this.description = description;
}
}
public static void main(String args[]) {
TestEnum t = new TestEnum();
t.setGender(Gender.M.name());
System.out.println("hashCode get: " + t.getGender().hashCode());
System.out.println("hashCode instance: " + t.gender.hashCode());
}
public String gender = null;
public void setGender(String gender){
this.gender = gender;
}
public Gender getGender(){
return Gender.valueOf(this.gender);
}
}
---------- END SOURCE ----------
JDK 1.7 Version
=============
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b22)
Java HotSpot(TM) Client VM (build 23.0-b21, mixed mode, sharing)
JDK 1.6 version
=============
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
System: Microsoft XP Professional version 2002 Service Pack 3
Version: 5.1.2600 Service Pack 3 Build 2600
A DESCRIPTION OF THE PROBLEM :
The hash code value is not stable in JDK 1.7, but t is same in JDK 1.6 if you run multiple time.
REGRESSION. Last worked in version 6u31
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Source code is attached. Kindly run the source code for the JDK version mentioned.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The hash code value is not stable in JDK 1.7
ACTUAL -
JDK 1.7
=======
G:\javapgms>java TestEnum
hashCode get: 18426253
hashCode instance: 77
G:\javapgms>java TestEnum
hashCode get: 3195425
hashCode instance: 77
G:\javapgms>java TestEnum
hashCode get: 3195425
hashCode instance: 77
JDK 1.6
======
G:\javapgms>java TestEnum
hashCode get: 11394033
hashCode instance: 77
G:\javapgms>java TestEnum
hashCode get: 11394033
hashCode instance: 77
G:\javapgms>java TestEnum
hashCode get: 11394033
hashCode instance: 77
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
The below program were tried in JDK 1.6 and JDK1.7
The hash code value is not stable in JDK 1.7, but it is same in JDK 1.6
class TestEnum {
enum Gender {
M("Male"), F("Female");
private String description;
Gender(String description){
this.description = description;
}
}
public static void main(String args[]) {
TestEnum t = new TestEnum();
t.setGender(Gender.M.name());
System.out.println("hashCode get: " + t.getGender().hashCode());
System.out.println("hashCode instance: " + t.gender.hashCode());
}
public String gender = null;
public void setGender(String gender){
this.gender = gender;
}
public Gender getGender(){
return Gender.valueOf(this.gender);
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-7191247 Reopening the Bug 7190798
- Closed
- relates to
-
JDK-8050217 Enum.hashCode() should return ordinal value for the enum, for better consistency
- Closed