Fix Duration config parsing for empty, uppercase and compound values - #14162
Closed
chirag-gamer wants to merge 2 commits into
Closed
Fix Duration config parsing for empty, uppercase and compound values#14162chirag-gamer wants to merge 2 commits into
chirag-gamer wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The
Durationconfig type used by options likelootables.refresh-min,lootables.refresh-maxandenvironment.delay-chunk-unloads-byparsed input by taking the unit from the last character and silently stripping everything else. That crashed withStringIndexOutOfBoundsExceptionwhen the value was empty, and turned values like10Hor1h30minto the wrong number of seconds.Fixes #14161
What changed:
10Hmeans 10 hours.1h30msum correctly instead of being mangled.abcor1h30is rejected with a clear error instead of silently becoming 0.Tested by running
DurationTestthrough 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 withStringIndexOutOfBoundsException,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.