GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix version comparison and parsing inconsistencies in maven-artifact by slachiewicz · Pull Request #12942 · apache/maven

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Aug 30, 2026

Copy link
Copy Markdown
Member

Three independent fixes in maven-artifact's version handling.

  • Release-qualifier ordering. 1-ga1 compared equal to 1, while 1-ga1 < 1-ga2. That breaks the transitivity contract Comparable requires, and contradicts the intent stated in the code's own comment (1-rc1 < 1, 1-ga1 > 1). CombinationItem.compareTo(null) consulted only the string part and never the digit. Includes a VersionRange-level regression test: an exact range [1.2.3] no longer matches 1.2.3-ga2.
  • hashCode/equals consistency. DefaultArtifactVersion.equals is defined via compareTo, but hashCode was structural, so two order-equal versions could hash differently. HashSet and TreeSet built from the same pair disagreed on size. equals and compareTo are unchanged, so no resolution outcome moves.
  • Parsing bound. ComparableVersion now rejects version strings longer than 256 characters. Nested - separators recurse per level and long digit runs cost quadratic time in BigInteger; on a reduced worker-thread stack the cold overflow floor is a few hundred levels. Nothing in this repository has a version string over 40 characters. Measurements are in the commit body.

Each fix is a separate commit and independently revertible.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
slachiewicz added 3 commits August 30, 2026 18:23
@slachiewicz
Bound ComparableVersion parsing to a maximum version string length
dfb1da9
Every '-' in a version string nests another list item, so comparison,
equality, hash code and canonicalization recurse one frame per level;
very long, deeply hyphenated version strings can exhaust the stack, and
very long digit runs cost quadratic time to parse into BigInteger.

Cap parseVersion's input at 256 characters, far beyond any real-world
version identifier, so all three costs stay bounded in one place.

Measurements behind the 256-character bound (this platform: macOS/
aarch64, one representative JDK; plausibly JDK- and platform-dependent,
worth re-checking on the Linux CI JVM before treating these thresholds
as authoritative elsewhere):
  - JIT-warmed, deep-vs-deep hashCode/equals/getCanonical overflow
    around 500 nested levels at a 256-500k thread stack size. (A
    comparison against a short, non-nested version such as "1" is not
    representative: it returns early on the first mismatched item type
    and never recurses, so it understates the risk.)
  - Cold, interpreter-only execution (-Xint, one shot per data point,
    representative of a freshly started JVM rather than a warmed-up
    long-running one, which matches how this code is normally invoked)
    against the smallest thread stack size the JVM will start at all on
    this platform (208k) overflows at as few as ~240 nested levels -
    below the ~256 levels a 512-character cap would allow. That
    combination is realistic enough (Maven runs as a fresh process, and
    embedders can and do configure small thread stacks) that a
    512-character cap could not be called clearly safe.
  - The same cold/interpreted measurement at a 228k stack overflows
    around 320-330 levels, giving the 256-character cap (~128 levels)
    roughly 2.4x headroom there, and ~1.8x headroom even at the 208k
    floor.

No compatibility cost identified: nothing in this repository's own
source, tests or POMs uses a version string longer than 40 characters,
and known long-form real-world version schemes (git-describe output,
Debian native versions, Eclipse OSGi qualifiers, timestamp-based
builds) stay well under 100.
@slachiewicz
Make DefaultArtifactVersion's hashCode consistent with its equals
f52721a
DefaultArtifactVersion.equals is defined as compareTo() == 0 (so, for
example, "1-ga" equals "1"), but its hashCode delegated to
ComparableVersion's structural hash, which does not agree: "1-ga" and
"1" parse to different item trees and therefore hash differently,
violating the equals/hashCode contract and breaking hash-based
collections built over repository version lists.

Add ComparableVersion.orderingHashCode(), a hash derived from the same
comparison rules compareTo() already uses (trailing null-equivalent
items dropped, qualifiers normalized), and have DefaultArtifactVersion
use it instead of the structural hash.
@slachiewicz
Fix release-qualifier-plus-digit versions comparing equal to the base…
2b6effd
… version

CombinationItem.compareTo(null) only consulted the string part, so a
release-equivalent qualifier ("ga", "final", "release") always compared
equal to null regardless of any trailing digit: "1-ga1" compared equal
to "1", and to "1-ga2" as well, while "1-ga1" itself sorts strictly
before "1-ga2". That breaks compareTo's transitivity contract and lets
a range or exact-version restriction match a differently-spelled
version it did not intend to: an exact pin [1.2.3] matched "1.2.3-ga2".

When the string part is release-equivalent, fall through to the digit
part so "1-ga1" sorts strictly after "1", matching the ordering the
surrounding comment already documents. Plain qualifiers with no digit
("1-ga") and a zero digit ("1-ga0") keep comparing equal to "1", as
documented elsewhere in this class.

Includes a range-level regression test demonstrating the exact-pin
scenario directly, alongside the ComparableVersion-level ordering test,
so a future cherry-pick of this fix cannot silently drop the coverage
that guards it.
@slachiewicz slachiewicz added the bug Something isn't working label Aug 30, 2026
@slachiewicz slachiewicz added this to the 4.0.0-rc-7 milestone Aug 30, 2026
@slachiewicz
slachiewicz requested review from cstamas, gnodet and slawekjaranowski August 30, 2026 19:06
gnodet
gnodet approved these changes Aug 30, 2026
View reviewed changes

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean backport of the version comparison fixes from master (#12947, already reviewed and approved) to maven-4.0.x. The diff is byte-for-byte identical to the master variant — all three fixes apply correctly:

  1. CombinationItem.compareTo transitivity — compareTo(null) now correctly delegates to digitPart.compareTo(null) when the string part is a release qualifier, restoring the transitivity contract.
  2. DefaultArtifactVersion hashCode/equals consistency — orderingHashCode() correctly strips trailing ordering-irrelevant items and normalizes qualifiers.
  3. ComparableVersion max length bound — properly enforced.

The CombinationItem class only exists in 4.x+, so no 3.9.x/3.10.x backport is needed for these fixes. Each fix is independently revertible via its own commit.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gnodet @claude
Address review: fix Javadoc punctuation and add ga11 test coverage
7f70d4a
- Fix sentence boundary in MAX_VERSION_LENGTH Javadoc (elharo review)
- Add Oxford comma for readability
- Add 1-ga11 to the ordering test to verify numeric (not lexicographic)
  comparison of multi-digit release qualifier suffixes

Co-Authored-By: Claude Opus 4.6 <[email protected]>
gnodet
gnodet approved these changes Sep 1, 2026
View reviewed changes

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delta re-review — Clean follow-up commit addressing reviewer feedback.

  • Javadoc punctuation — Semicolon → period, Oxford comma added in ComparableVersion.java.
  • Test coverage — 1-ga11 added to checkVersionsOrder, verifying multi-digit release qualifier suffixes are compared numerically (11 > 9), not lexicographically. Well-targeted — this is exactly the edge case where lexicographic comparison fails.

No new issues. Previous APPROVE still valid.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gnodet
gnodet merged commit fe4e99b into apache:maven-4.0.x Sep 2, 2026
22 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot assigned gnodet Sep 2, 2026
@slachiewicz
slachiewicz deleted the pr/version-comparison-4.0.x branch September 19, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gnodet gnodet gnodet approved these changes
@cstamas cstamas Awaiting requested review from cstamas
@slawekjaranowski slawekjaranowski Awaiting requested review from slawekjaranowski

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@gnodet gnodet

Labels

bug Something isn't working

Projects

None yet

Milestone

4.0.0-rc-7

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@slachiewicz @gnodet
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.