1. Maven
  2. MNG-3047

DefaultArtifactVersion compareTo inconsistent with equals


    • Flags:


      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.


        Issue Links


          David Julian created issue -
          David Julian made changes -
          Field Original Value New Value
          Attachment MNG-3047-maven-artifact.patch [ 27913 ]
          David Julian made changes -
          Link This issue is related to MNG-3046 [ MNG-3046 ]
          Jason van Zyl made changes -
          Fix Version/s Reviewed [ 13555 ]
          Brett Porter made changes -
          Component/s Artifacts [ 12035 ]
          Component/s Artifacts and Repositories [ 11338 ]
          John Casey made changes -
          Assignee John Casey [ jdcasey ]
          John Casey made changes -
          Fix Version/s 2.1-alpha-1 [ 13143 ]
          Resolution Fixed [ 1 ]
          Fix Version/s 2.0.8 [ 13139 ]
          Fix Version/s Reviewed Pending Version Assignment [ 13555 ]
          Status Open [ 1 ] Closed [ 6 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 08:49:45 UTC 2015 [ 1428223785911 ]
          Mark Thomas made changes -
          Workflow jira [ 12713544 ] Default workflow, editable Closed status [ 12753328 ]
          Mark Thomas made changes -
          Patch Submitted Yes [ 10763 ]
          Flags Patch [ 10430 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 21:45:26 UTC 2015 [ 1428270326204 ]
          Mark Thomas made changes -
          Workflow jira [ 12952223 ] Default workflow, editable Closed status [ 12989574 ]


            • Assignee:
              John Casey
              David Julian
            • Votes:
              0 Vote for this issue
              1 Start watching this issue


              • Created: