Skip to content

fix(base-option): reimplement JDKVersion on top of Runtime.Version - #106

Merged
deer merged 1 commit into
mainfrom
jdk_version_fix
Aug 31, 2026
Merged

fix(base-option): reimplement JDKVersion on top of Runtime.Version#106
deer merged 1 commit into
mainfrom
jdk_version_fix

Conversation

@deer

@deer deer commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

JDKVersion.of("25.0.4.1") did not compare as newer than JDKVersion.of("25.0.4"). The hand-written parser only ever populated major, minor, and security from the first three dotted elements and dropped any fourth element, so a four-segment version such as an Azul-style $PATCH respin was parsed as if it were 25.0.4 and compareTo returned 0.

The fix reimplements JDKVersion as a thin wrapper around a single parsed Runtime.Version, which models the full dotted version-number sequence and provides a correct ordering. compareTo, equals, hashCode, toString, and every accessor (major(), minor(), security(), build(), pre(), optional(), version(), isModular()) now delegate to the wrapped value. A new runtimeVersion() accessor exposes it directly. This replaces roughly 330 lines of position-scanning parser and its parallel field set.

Modern strings are passed straight to Runtime.Version.parse(String). Legacy pre-Java-9 strings (those starting with 1.) are first normalized: a regex remaps 1.x to the modern scheme, dropping the leading 1., folding the _update segment into the dotted version number (so 1.8.0_292 becomes 8.0.292), and turning -bNN into +NN. Trailing .0 elements, which Runtime.Version rejects but legacy strings and some tooling emit, are stripped, so 25.0.4.0 still normalizes to and compares equal to 25.0.4.

equals is now defined as compareTo(other) == 0 and hashCode returns version.hashCode(). This is consistent because Runtime.Version.compareTo compares the same four components (version, pre, build, optional) that Runtime.Version.equals and hashCode use, and because normalization guarantees no instance retains trailing zero elements, so any two instances that compare equal have identical component lists.

This also drops the base-foundation dependency from base-option (both pom.xml and module-info.java), since Strings was its only use and no other module in the repository consumes JDKVersion.

Behavior changes for callers: toString() now returns the normalized modern-scheme form rather than a custom rendering; get() still returns the raw input, and for current() that raw value now comes from Runtime.version() instead of the java.version system property; and of(String) now throws IllegalArgumentException for null, blank, or unparseable input rather than NoSuchElementException or a bare RuntimeException.

@deer
deer merged commit c78ffc0 into main Aug 31, 2026
3 checks passed
@deer
deer deleted the jdk_version_fix branch August 31, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant