United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6921374 java.lang.String::hashCode() should check for count == 0 to avoid repeated stores hash = 0
JDK-6921374 : java.lang.String::hashCode() should check for count == 0 to avoid repeated stores hash = 0

Details
Type:
Enhancement
Submit Date:
2010-01-29
Status:
Resolved
Updated Date:
2010-07-09
Project Name:
JDK
Resolved Date:
2010-03-17
Component:
core-libs
OS:
solaris_10
Sub-Component:
java.lang
CPU:
sparc
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Relates:

Sub Tasks

Description
java.lang.String::hashCode() should check for count == 0 to avoid repeated stores hash = 0.
Something like this:

    public int hashCode() {
        int h = hash;
-       if (h == 0) {
+      if (h == 0 && count > 0) {
            int off = offset;
            char val[] = value;
            int len = count;

            for (int i = 0; i < len; i++) {
                h = 31*h + val[off++];
            }
            hash = h;
        }
        return h;
    }

                                    

Comments
EVALUATION

Fixed as per suggestion in jdk7.
                                     
2010-03-03



Hardware and Software, Engineered to Work Together