[ 
http://jira.codehaus.org/browse/MNG-3047?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

John Casey closed MNG-3047.
---------------------------

       Resolution: Fixed
    Fix Version/s:     (was: Reviewed Pending Version Assignment)
                   2.1-alpha-1
                   2.0.8

Applied. Thanks!

> DefaultArtifactVersion compareTo inconsistent with equals
> ---------------------------------------------------------
>
>                 Key: MNG-3047
>                 URL: http://jira.codehaus.org/browse/MNG-3047
>             Project: Maven 2
>          Issue Type: Improvement
>          Components: Artifacts and Repositories
>    Affects Versions: 2.0.6
>            Reporter: David Julian
>            Assignee: John Casey
>            Priority: Minor
>             Fix For: 2.0.8, 2.1-alpha-1
>
>         Attachments: MNG-3047-maven-artifact.patch
>
>
> Over the course of investigating MNG-3046, I discovered 
> DefaultArtifactVersion's implementation of Comparable.compareTo() is 
> inconsistent with its equals(Object).  (DefaultArtifactVersion doesn't 
> implement equals(...); it's using the instance equals it gets from Object.)  
> The contract for Comparable.compareTo()[1] states, while it's not strictly 
> required the behavior between compareTo and equals be consistent, breaking it 
> should be an overt and visible decision.  In the case of 
> DefaultArtifactVersion, there's really no reason not to implement equals and 
> hashCode.
> I have a fix--I'll attach a patch shortly--that implements equals and 
> hashCode following the recipes from Bloch's "Effective Java."  In fact, 
> equals now uses a cleaned-up compareTo, ensuring consistency across these 
> methods.
> Since the interface ArtifactVersion extends Comparable (as opposed to 
> DefaultArtifactVersion implementing both ArtifactVersion and Comparable) I 
> assume the intent is to be able to compare different ArtifactVersions 
> regardless of implementation.  Therefore, I added the equals and hashCode 
> declaration to the interface and made the equals and compareTo 
> implementations work with all ArtifactVersions.
> Note that this work obviates the patch for MNG-3046.  I made that patch small 
> and surgical to fix a major issue.  This fix is less urgent--still important, 
> imho--but I wasn't sure if the interface changes were right for the whole 
> project, if such a big change is warranted, etc.  The bottom line is: only 
> that patch or this one need be applied, not both.
> [1] 
> http://java.sun.com/javase/6/docs/api/java/lang/Comparable.html#compareTo(T)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to