commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephan Schuster <st...@wilken.de>
Subject [vfs] Why doesn't AbstractFileObject override equals?
Date Wed, 11 Jun 2008 16:34:24 GMT
hi together,

on the first glimpse i don't understand why AbstractFileObject doesn't 
override equals() and hashCode(). depending on the concrete 
implementation this may result in Object's identity comparison when 
comparing two file objects which is in most cases definitely not desired 
(see further below). in my opinion a simple solution would be:


     @Override
     public boolean equals(final Object other) {
         if (this == other)
             return true;
         if (other == null)
             return false;
         if (!(other instanceof FileObject))
             return false;

         try {
             return getURL().equals(((FileObject) other).getURL());
         } catch (FileSystemException e) {
             return false;
         }
     }

     @Override
     public int hashCode() {
         try {
             return getURL().hashCode();
         } catch (FileSystemException e) {
             return super.hashCode();
         }
     }


another issue i stumbled upon today: in AbstractFileObject.getParent() 
there's an if-clause like:

     if (this == fs.getRoot()) { ... }

i'm pretty sure that an identity comparison makes no sense here and this 
should rather be changed to

     if (this.equals(fs.getRoot())) { ... }

however, this will only work if equals() is overridden.


what do you think?


regards,
stephan


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message