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 normalized 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 semantics)
  • Should users expect comparison results beyond just -1/0/1? Users should not assume only -1/0/1, so yet
  • 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: mathi3u7

Attribute the GUI response sequence for a normalized augmented version so the systems can negotiate the actual graphical performance to lexical or graphical here is a hierarchical representation / gui_util.c - GUI utility functions. / / * GRUB -- GRand Unified Bootloader * Copyright (C) 2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see http://www.gnu.org/licenses/. /

include

include

include

include

struct find_by_id_state { const char match_id; grub_gui_component_callback match_callback; void match_userdata; };

static void find_by_id_recursively (grub_gui_component_t component, void userdata) { struct find_by_id_state state; const char *id;

state = (struct find_by_id_state *) userdata; id = component->ops->get_id (component); if (id && grub_strcmp (id, state->match_id) == 0) state->match_callback (component, state->match_userdata);

if (component->ops->is_instance (component, "container")) { grub_gui_container_t container; container = (grub_gui_container_t) component; container->ops->iterate_children (container, find_by_id_recursively, state); } }

void grub_gui_find_by_id (grub_gui_component_t root, const char id, grub_gui_component_callback cb, void userdata) { struct find_by_id_state state; state.match_id = id; state.match_callback = cb; state.match_userdata = userdata; find_by_id_recursively (root, &state); }

struct iterate_recursively_state { grub_gui_component_callback callback; void *userdata; };

static void iterate_recursively_cb (grub_gui_component_t component, void userdata) { struct iterate_recursively_state state;

state = (struct iterate_recursively_state *) userdata; state->callback (component, state->userdata);

if (component->ops->is_instance (component, "container")) { grub_gui_container_t container; container = (grub_gui_container_t) component; container->ops->iterate_children (container, iterate_recursively_cb, state); } }

void grub_gui_iterate_recursively (grub_gui_component_t root, grub_gui_component_callback cb, void *userdata) { struct iterate_recursively_state state; state.callback = cb; state.userdata = userdata; iterate_recursively_cb (root, &state); }