Hi,

I came across a case where I was comparing two Version objects like this:

Version version1 = new Version(1, 0, 0, "alpha");
Version version2 = new Version(1, 0, 0, "snapshot");
int result = version1.compareTo(version2);
System.out.println(result); // returns -18

I was a bit confused by the result -18, which comes from a lexicographical comparison of the snapshot info strings. I had initially expected "alpha" to be considered newer than "snapshot", or for the comparison to return a normalized result like -1, 0, or 1.

I’d like to ask:

  • Is this the intended behavior, or could it be considered a bug?

  • Is the snapshot info string always compared lexicographically?

  • Should users expect comparison results beyond just -1/0/1?

  • Is there any semantic ordering (e.g., "alpha" < "beta" < "rc" < "snapshot"), or is this left entirely to user interpretation?

Clarifying this in the Javadoc or documentation would help prevent confusion for users relying on version comparison behavior.

Thanks!

Comment From: pjfanning

This is an internal class. It is not part of the public Jackson API. Jackson is a lib for parsing and generating JSON. It is not a lib for comparing version strings. There are libs that specialise in that sort of thing. Semver4J is one.

Comment From: cowtowncoder

Right, maybe Version should not even be Comparable, but the intent definitely is for it to only be used for Jackson components and extension Modules. Latter can be from external developers. But the main intent is for visibility, and (to a degree) to allow for compatibility comparison wrt version numbers. Classifier String ordering is not really defined, esp. wrt SNAPSHOT vs alpha.

Note on numeric value: I don't think compareTo() is expected to normalize value: they are to be only used for "is it 0, less than 0 or greater than 0" comparison. With that, I think that:

  • Is this the intended behavior, or could it be considered a bug? Not a bug
  • Is the snapshot info string always compared lexicographically? Yes, String qualifier/classifier part is to be sorted lexicographically (without other implied semantics)
  • Should users expect comparison results beyond just -1/0/1? Users should not assume only -1/0/1 (I don't think contract for compareTo() specifies that) so yes
  • Is there any semantic ordering (e.g., "alpha" < "beta" < "rc" < "snapshot"), or is this left entirely to user interpretation? No semantic ordering -- Maven has utility classes for users who'd like to get useful semantic ordering.

Comment From: cowtowncoder

I think things work as intended: I'd be open for Javadoc improvements to clarify intent. But behavior-wise, just to summarize:

  1. The last part is considered arbitrary String, with no semantic ordering implied; sorted lexicographically
  2. Result for compareTo() is NOT normalized but simply produces 0, > 0 or < 0 values for ordering