[jcifs] Bug in implementation of jcifs.smb.SmbFile#equals(Object).

Michael B Allen miallen at ioplex.com
Fri Feb 22 16:58:59 GMT 2008


Hi Andreas,

The hashCode method considers the server address and path.

Please provide two URLs that compare to true and explain why you think
that they should not.

Perhaps we just need to tweak the hashCode method.

Or are you seeing hash value collisions?

Mike

On Fri, 22 Feb 2008 09:45:13 +0100
Andreas Salathe <asal at zrh.che.xerox.com> wrote:

> Hi,
> SmbFile.equals(Object o) just checks on the hashCode() for checking 
> equality and thus eventually
> returns true, even if the compared SmbFile's are clearly distinct.
> 
> current impl: (jcifs_1.2.18, SmbFile.java)
> 
>     public boolean equals( Object obj ) {
>          return obj instanceof SmbFile && obj.hashCode() == hashCode();
>     }
> 
> 
> possible fixup:
> 
>     public boolean equals( Object obj ) {
>         if (! ( obj instanceof SmbFile ))
>             return false;
> 
>         SmbFile of = (SmbFile)obj;
>         String addr;
>         try {
>             addr = getAddress().toString(); }
>         catch (UnknownHostException uhe) {
>             addr = getServer().toUpperCase(); }
> 
>         String oaddr;
>         try {
>             oaddr = of.getAddress().toString(); }
>         catch (UnknownHostException uhe) {
>             oaddr = of.getServer().toUpperCase(); }
>         
>         if (!addr.equals(oaddr)) return false;
>         getUncPath0();
>         of.getUncPath0();
>         return canon.toUpperCase().equals(of.canon.toUpperCase());
>    }
> 
> 
> 


-- 
Michael B Allen
PHP Active Directory SPNEGO SSO
http://www.ioplex.com/


More information about the jcifs mailing list