Skip to content

Tolerate non-numeric segments in Bukkit.getBukkitVersion() (McVersion) - #859

Open
ch4ika wants to merge 2 commits into
devnatan:mainfrom
ch4ika:fix/mcversion-non-numeric-server-version
Open

Tolerate non-numeric segments in Bukkit.getBukkitVersion() (McVersion)#859
ch4ika wants to merge 2 commits into
devnatan:mainfrom
ch4ika:fix/mcversion-non-numeric-server-version

Conversation

@ch4ika

@ch4ika ch4ika commented Aug 25, 2026

Copy link
Copy Markdown

Problem

Some server forks append build/commit metadata to Bukkit.getBukkitVersion() as extra dot-separated segments (e.g. 26.2.build.17406-6bc38be). McVersion's static initializer assumes every dot-separated segment before the first - is numeric and calls Integer.parseInt directly on it, so a segment like build throws a NumberFormatException.

Because this happens in a static initializer, the failure is permanent for the classloader's lifetime (ExceptionInInitializerError, later NoClassDefFoundError) and takes down every feature that touches McVersion — in our case the anvil input feature, breaking any menu that used it to collect text input.

Fix

  • McVersion now reads only the leading run of numeric major[.minor[.patch]] segments via a regex lookingAt() match, ignoring anything after the first non-numeric segment, instead of throwing.
  • nextGitTag() in the root build.gradle.kts ran git describe against the Gradle process's working directory rather than the project directory (providers.exec doesn't default to projectDir), which only worked by coincidence when this project was built standalone. Included as a composite build from another project, it resolved the wrong repository and failed. Fixed by passing workingDir(project.projectDir) explicitly.

Testing

Verified against a full downstream build (Paper plugin consuming this library via a Gradle composite build) — McVersion.current() no longer throws, and the anvil input feature works again on the affected server fork.

ch4ika added 2 commits August 25, 2026 10:30
…ving McVersion

Some server forks append build/commit metadata as extra dot-separated
segments (e.g. "26.2.build.17406-6bc38be"), which is not numeric and
made the McVersion static initializer throw a NumberFormatException,
permanently breaking any feature that touches this class (anvil input
included) for the lifetime of the classloader.

McVersion now reads only the leading run of numeric major[.minor[.patch]]
segments and ignores anything after the first non-numeric one.
providers.exec defaults to the Gradle process's working directory, not
the project directory, so nextGitTag() ran 'git describe' against
whatever repository the build happened to be invoked from. That only
worked by coincidence when this project was built standalone from its
own root; included as a composite build from another project it ran
git against the wrong repository and failed.
@ch4ika
ch4ika marked this pull request as ready for review August 26, 2026 07:55
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.

2 participants