Bugs item #990011, was opened at 2004-07-13 02:06
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=536613&aid=990011&group_id=73068

Category: main tag library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: Algorithm in org.displaytag.util.ParamEncoder is bogus

Initial Comment:
The algorithm used in the ParamEncoder-class produces 
easily colliding keys, e.g. "option" and "answer". 

If there isn't a reason to exchange hashes between 
different JRE:s (let the difference be vendor or version), 
why not use the  hashCode() provided by 
java.lang.String? The hash is cached as well, which 
might help interned Strings.

If you wan't to keep the hash backwards compat, I 
suggest you use a better algo, for example the one 
described by Joshua Bloch (copy-paste from my patched 
class):

        // Joshua Bloch, Effective Java, p. 38-39
        int checkSum = 17;
     
        for (int j = 0; j < charArray.length; j++)
        {
            checkSum = 37 * checkSum + (int) charArray[j];
        }
        
        // keep it positive
        checkSum &= 0x7fffffff;
        
The downside of this algo is the length of the hash, but it 
may be controlled with the number 37: lower primes yeild 
less length. Other option is to let less bits through the 
and-mask.

Questions/comments are welcome, my mailname is villeja 
and the domain is avoltus.com. Combine those =).

-Ville

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=536613&aid=990011&group_id=73068


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
displaytag-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/displaytag-devel

Reply via email to