Skip to content

Fix StringIndexOutOfBoundsException on new Minecraft version scheme (26.x) - #59

Open
BinSlayer01 wants to merge 1 commit into
CuzIm1Tigaaa:masterfrom
BinSlayer01:fix/version-parse-26x
Open

Fix StringIndexOutOfBoundsException on new Minecraft version scheme (26.x)#59
BinSlayer01 wants to merge 1 commit into
CuzIm1Tigaaa:masterfrom
BinSlayer01:fix/version-parse-26x

Conversation

@BinSlayer01

Copy link
Copy Markdown

Problem

On Minecraft's new year-based version scheme (e.g. 26.1.2), the plugin fails to enable with:

java.lang.StringIndexOutOfBoundsException: Range [0, 2) out of bounds for length 1
    at de.cuzim1tigaaa.spectator.files.Config.loadConfig(Config.java:40)
    at de.cuzim1tigaaa.spectator.Spectator.reload(Spectator.java:75)
    at de.cuzim1tigaaa.spectator.Spectator.register(Spectator.java:54)
    at de.cuzim1tigaaa.spectator.Spectator.onEnable(Spectator.java:36)

Cause

Config.loadConfig() derives the major version with:

int serverVersion = Integer.parseInt(getBukkitVersion().split("\.")[1].substring(0, 2));

This assumes the legacy 1.X.Y format, where split(".")[1] is the minor ("21", "20", …). With the new scheme, getBukkitVersion() is e.g. "26.1.2-R0.1-SNAPSHOT", so split(".")[1] is "1" — only one character — and substring(0, 2) throws.

Fix

Parse defensively: strip the build suffix, then treat a leading 1. as the legacy scheme (gate on the minor) and any other leading number as a modern version (≥ 1.18 behaviour).

String[] versionParts = plugin.getServer().getBukkitVersion().split("-")[0].split("\.");
int serverVersion = versionParts[0].equals("1") && versionParts.length > 1
        ? Integer.parseInt(versionParts[1])
        : 99;

Testing

Built and ran on Spigot 26.1.2: the plugin now enables cleanly, config + messages load, and commands register. Verified the legacy path still behaves the same for 1.x versions.

Note: a separate, harmless warning remains on Spigot (PaperListener can't register PlayerAdvancementCriterionGrantEvent — a Paper-only event); that's pre-existing and gracefully handled, out of scope for this fix.

Config.loadConfig() parsed the major version with
getBukkitVersion().split(".")[1].substring(0, 2), assuming the legacy
"1.X.Y" format. On the new year-based scheme (e.g. "26.1.2") the second
component is "1", so substring(0, 2) throws StringIndexOutOfBoundsException
and the plugin fails to enable.

Parse defensively: strip the build suffix, then treat a leading "1." as the
legacy scheme (use the minor as the version gate) and any other leading
number as a modern version (>= 1.18 behaviour).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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