JDK-6921374 : java.lang.String::hashCode() should check for count == 0 to avoid repeated stores hash = 0
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_10
  • CPU: sparc
  • Submitted: 2010-01-29
  • Updated: 2010-07-09
  • Resolved: 2010-03-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u21Fixed 7 b86Fixed
Related Reports
Relates :  
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.
03-03-2010