mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FTPSERVER-375) [FindBugs] NativeFtpFile implements equals(), but does not - hashCode()
Date Sun, 19 Jun 2011 14:01:47 GMT

    [ https://issues.apache.org/jira/browse/FTPSERVER-375?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13051685#comment-13051685

Sebb commented on FTPSERVER-375:

However, equals() and hashCode() are not calculated simulataneously, so if the external conditions
change between calling the two methods, they may disagree.

Further, a hashCode should not change if the object does not change (and should not change
at all if used in some kinds of map).

It would be safer to fetch the canonical path once, and base the methods on that.

This would need to be stored in a volatile field and made package-protected (or better with
a package-protected getter) for access by equals().

Should use getCanonicalPath() - not File() - which is a String, so is immutable.

But again - is the equals method needed?
And if so, what does it mean to be equal to another instance?
This affects how the methods need to be coded.

Also I agree that the equals method needs to be documented if it is kept.

> [FindBugs] NativeFtpFile implements equals(), but does not - hashCode()
> -----------------------------------------------------------------------
>                 Key: FTPSERVER-375
>                 URL: https://issues.apache.org/jira/browse/FTPSERVER-375
>             Project: FtpServer
>          Issue Type: Wish
>          Components: Core
>            Reporter: Sergey Vladimirov
>            Priority: Minor
>              Labels: equality, findbugs
>             Fix For: 1.0.6, 1.1.0
> In fact, i can't find why it need to implement equals() in first place. If for any map
- then hashCode() will also be required. For example, this.file.getCanonicalFile().hashCode()
> Anyway, could we please have a comment why do we need equals() method? :)

This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira


View raw message