Skip to content

Fix Duration config parsing for empty, uppercase and compound values - #14162

Closed
chirag-gamer wants to merge 2 commits into
PaperMC:mainfrom
chirag-gamer:fix/duration-config-parsing
Closed

Fix Duration config parsing for empty, uppercase and compound values#14162
chirag-gamer wants to merge 2 commits into
PaperMC:mainfrom
chirag-gamer:fix/duration-config-parsing

Conversation

@chirag-gamer

@chirag-gamer chirag-gamer commented Aug 8, 2026

Copy link
Copy Markdown

The Duration config type used by options like lootables.refresh-min, lootables.refresh-max and environment.delay-chunk-unloads-by parsed input by taking the unit from the last character and silently stripping everything else. That crashed with StringIndexOutOfBoundsException when the value was empty, and turned values like 10H or 1h30m into the wrong number of seconds.

Fixes #14161

What changed:

  • Empty or whitespace-only values now surface a clear config error instead of throwing an index out of bounds exception.
  • Units parse case-insensitively, so 10H means 10 hours.
  • Compound durations like 1h30m sum correctly instead of being mangled.
  • Invalid input like abc or 1h30 is rejected with a clear error instead of silently becoming 0.

Tested by running DurationTest through the Normal test suite locally (the parser is standalone, no registry values needed). All 7 cases pass. Before changing anything I also confirmed the old behavior with a small harness: empty value crashed with StringIndexOutOfBoundsException, 10H -> 10 seconds, 1h30m -> 7800 seconds. I did not run the whole server test suite, just the Normal suite.

One judgment call: the docs describe durations as a single unit, so compound support goes a bit past what's documented. It felt less surprising than rejecting 1h30m, but I can tighten it to reject instead if you'd rather keep the contract strict.

getSeconds() took the unit from the last character and silently stripped
everything else, so an empty value crashed with StringIndexOutOfBoundsException
and values like 10H or 1h30m parsed to the wrong number of seconds. Parse units
case-insensitively, support compound durations, and reject empty or invalid
input with a clear error instead of crashing.
@github-project-automation github-project-automation Bot moved this from Awaiting review to Closed in Paper PR Queue Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

Duration config values: empty string crashes on load, uppercase unit silently means seconds

2 participants