Repository navigation
ZmanimFormatter.setTimeFormat: leave the formatter unchanged when the value is invalid - #303
Merged
KosherJava merged 1 commit intoNov 6, 2026
Conversation
… is invalid timeFormat was assigned before the value was validated, so an invalid value threw IllegalArgumentException but left the formatter in a mixed state: a formatter using XSD_DURATION_FORMAT went on to format durations as "1:30" with the settings of the last sexagesimal format instead of "PT1H30M". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015Er4Sx7LnKzzCbgDEatxkU
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 issue
ZmanimFormatter.setTimeFormat(int)throwsIllegalArgumentExceptionfor an invalid value, but only after it has already changed the formatter. That leaves the formatter in a state that matches neither the old format nor the new one.The edge case
Calling
setTimeFormatwith a value that isn't one of the five constants, such as a format read from preferences or a config file. Callers can reasonably expect to catch the exception and keep the previous format.What happens
this.timeFormat = format;runs before theswitchvalidatesformat. The switch then throws, buttimeFormatnow holds the invalid value. If the formatter was usingXSD_DURATION_FORMAT,format(Duration)stops using it and falls back to whatever sexagesimal settings were last applied:The fix
Validate first: assign
timeFormatafter theswitch, once the value is known to be valid. An invalid value now throws and leaves the formatter unchanged, which the Javadoc now states. Valid values behave exactly as before.Tests
ZmanimFormatterTimeFormatTest:PT1H30M. This fails without the fix.1:30, and a valid change afterwards works.🤖 Generated with Claude Code
https://claude.ai/code/session_015Er4Sx7LnKzzCbgDEatxkU