Issue Details (XML | Word | Printable)

Key: MNG-3046
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: John Casey
Reporter: David Julian
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Maven 2 & 3

DefaultArtifactVersion compareTo misbehaves regarding buildNumber 0

Created: 11/Jun/07 01:44 PM   Updated: 14/Aug/07 10:22 AM   Resolved: 14/Aug/07 10:22 AM
Component/s: Artifacts and Repositories
Affects Version/s: 2.0.6
Fix Version/s: 2.0.8, 3.0-alpha-1

Time Tracking:
Not Specified

File Attachments: 1. Text File MNG-3046-maven-artifact.patch (3 kB)

Issue Links:
Related
 

Patch Submitted: Yes


 Description  « Hide

The implementation of Comparable.compareTo(Object) is faulty regarding the handling of version numbers where a build number is present but zero. Here's a unit test to demonstrate:

DefaultArtifactVersion v1 = new DefaultArtifactVersion("2.0");
DefaultArtifactVersion v2 = new DefaultArtifactVersion("2.0-0");
DefaultArtifactVersion v3 = new DefaultArtifactVersion("2.0-alpha1");

// v1 and v2 are equal
assertTrue( v1.compareTo(v2) == 0 );
assertTrue( v2.compareTo(v1) == 0 );

// v1 is newer than v3
assertTrue( v1.compareTo(v3) > 0 );
assertTrue( v3.compareTo(v1) < 0 );

// ergo, v2 should also be newer than v3
assertTrue( v2.compareTo(v3) > 0 ); // FAILS!! returns 0 (equal)
assertTrue( v3.compareTo(v1) < 0 ); // succeeds

This test demonstrates this behavior violates symmetry and transitivity.

Luckily, the fix is easy. A small change to the compareTo method to consider qualifiers before build numbers relieves this issue. I have a patch that I'll submit as soon as I have the issue number.



David Julian added a comment - 11/Jun/07 01:48 PM

This patch modifies:

org.apache.maven.artifact.versioning.DefaultArtifactVersion
org.apache.maven.artifact.versioning.DefaultArtifactVersionTest

I followed the instructions on creating the patch here: http://maven.apache.org/guides/development/guide-m2-development.html#Creating%20and%20submitting%20a%20patch


John Casey added a comment - 14/Aug/07 10:22 AM

Applied, thanks.