Skip to content

Zero week value conversion fails with 'intValue cannot be extracted from WEEKS' exception - #51892

Merged
philwebb merged 2 commits into
spring-projects:4.0.xfrom
LindseyZ1205:fix/zero-period-week-format
Sep 28, 2026
Merged

philwebb merged 2 commits into
spring-projects:4.0.xfrom
LindseyZ1205:fix/zero-period-week-format

Conversation

@LindseyZ1205

Copy link
Copy Markdown
Contributor

Formatting Period.ZERO with PeriodStyle.SIMPLE and ChronoUnit.WEEKS throws IllegalStateException: intValue cannot be extracted from WEEKS. The same failure occurs through ApplicationConversionService when a period has @PeriodFormat(SIMPLE) and @PeriodUnit(WEEKS).

For zero periods, format the zero directly with the selected unit's suffix. This avoids extracting a weeks component that Period does not expose. Non-zero periods continue to use years, months, and days, as intended in #22225.

Reproduced on main at 5f790ed584b269bce1ace8f8e73a15cc177dcad2:

PeriodStyle.SIMPLE.print(Period.ZERO, ChronoUnit.WEEKS);
// Expected: "0w"
// Actual: IllegalStateException

Validation:

  • On the original source, the three new regression cases fail; the other 37 cases pass.
  • With the fix, all 40 PeriodStyle and PeriodToStringConverter cases pass.
  • The converter regression covers both an isolated converter and ApplicationConversionService.
  • Core formatting and Checkstyle main/test checks pass.
  • All 259 tests in the conversion package pass.
  • The full core check did not pass: 3,842 tests, 6 failures in JavaLoggingSystemTests, and 15 skipped. Restoring the original production behavior reproduced these same six failures, plus seven other logging failures and the three new regression failures. A subsequent conversion/JavaLoggingSystemTests run passed all conversion tests and reproduced the same six Java logging failures. The logging failures remain undiagnosed.
  • The full multi-module build was not run.

AI disclosure: I used Codex for investigation, implementation, regression tests, local checks, and drafting this description.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. label Sep 28, 2026
@philwebb philwebb self-assigned this Sep 28, 2026
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. labels Sep 28, 2026
@philwebb philwebb added this to the 4.0.x milestone Sep 28, 2026
@philwebb philwebb changed the title Fix formatting a zero period with a weeks unit Zero week value conversion fails with 'intValue cannot be extracted from WEEKS' exception Sep 28, 2026
@philwebb
philwebb changed the base branch from main to 4.0.x September 28, 2026 16:10
@philwebb
philwebb force-pushed the fix/zero-period-week-format branch from 55a81df to d9df34b Compare September 28, 2026 16:10
@philwebb
philwebb merged commit e4b2ecf into spring-projects:4.0.x Sep 28, 2026
1 check failed
@philwebb philwebb modified the milestones: 4.0.x, 4.0.9 Sep 28, 2026
@philwebb

Copy link
Copy Markdown
Member

Thanks very much @LindseyZ1205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants