Bugs item #990011, was opened at 2004-07-13 11:06
Message generated for change (Comment added) made by fgiust
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: Deleted
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

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

>Comment By: fabrizio giustina (fgiust)
Date: 2004-09-22 14:28

Message:
Logged In: YES 
user_id=798060

moved to the new jira tracker
http://jira.codehaus.org/browse/DISPL-12

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

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


-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
displaytag-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/displaytag-devel

Reply via email to