Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Is it worth commenting that Strings.common* expose potential memory leak from JDK String?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Maaartin G  
View profile  
 More options Jul 2 2012, 10:17 am
From: Maaartin G <grajc...@seznam.cz>
Date: Mon, 2 Jul 2012 07:17:07 -0700 (PDT)
Local: Mon, Jul 2 2012 10:17 am
Subject: Re: [guava] Is it worth commenting that Strings.common* expose potential memory leak from JDK String?

On Monday, July 2, 2012 12:10:54 PM UTC+2, Éamonn McManus wrote:

> If I recall correctly, the String.hashCode() algorithm used to be
> specified directly in the JLS. And, the original algorithm was
> different: it would sample characters from longer strings rather than
> examining all of them. So back then it was felt that the algorithm
> *could* be changed, but meanwhile such a huge amount of Java code has
> built up that changing it now would indeed be sure to break a
> nontrivial amount of code. Too bad, though, that when it could be
> changed it wasn't changed to something less awful.

In the first place it should never have been specified. But I would not
call the algorithm awful, although I see no reason for it working the way
it does:

- Multiplication by 31 can't be optimized especially well using
instructions like LEA.
- There's no reason for using a prime here, any odd number sort of works
here.
- It leads to many trivial collision even for strings of length 2.

Switching to any other deterministic algorithm does NOT help at all. Even
with the (truncated) secure hash, finding collisions in 32 bits is very
easy and finding multicollisions is feasible. Finding N strings hashing to
0 needs about N*2**31 operations, so in a few hours I could compute
thousands of them.

The determinism is the main problem here, the particular algorithm doesn't
matter.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.