Repository navigation
WW-5814 Opt-in offset-aware ISO date-times for java.util.Date - #2059
Merged
Merged
Conversation
….util.Date DateConverter reads the Z of an ISO date-time such as 2026-10-25T05:14:42.000Z as a literal, so a UTC timestamp from a client is interpreted in the server's default time zone. Reading it correctly shifts every such value by the server's offset without a conversion error, so it is opt-in for 7.5.0: struts.converter.date.isoOffsetAware, default false. WW-5815 flips the default in 8.0.0. When enabled, a java.util.Date target (and Calendar, which converts through it) first tries DateTimeFormatter.ISO_OFFSET_DATE_TIME: Z means UTC, numeric offsets are honoured and 0-9 fractional digits are read as a fraction. Input without an offset falls through to the existing formats unchanged. A year outside Date's range is a conversion error. The Z tests pin Asia/Tokyo as the default zone, so they cannot pass vacuously on a UTC build machine. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
Static review found no blocking issues in the opt-in behavior, configuration wiring, or regression coverage; tests were not executed during this review.
No open issues 🎉
What changed in this PR
Adds opt-in offset-aware ISO date-time parsing for java.util.Date in Struts, preserving existing behavior by default.
Changes:
- Introduces
struts.converter.date.isoOffsetAware, defaulting tofalse. - Parses UTC and numeric offsets when enabled, with conversion errors for dates outside the supported range.
- Adds regression tests for configuration wiring, offsets, fractional seconds, and legacy fallback behavior.
| File | Description |
|---|---|
| core/src/test/java/org/apache/struts2/conversion/impl/DateConverterTest.java | Tests opt-in parsing and backward compatibility. |
| core/src/main/resources/org/apache/struts2/default.properties | Documents and disables the option by default. |
| core/src/main/java/org/apache/struts2/StrutsConstants.java | Defines the public configuration constant. |
| core/src/main/java/org/apache/struts2/conversion/impl/DateConverter.java | Implements offset-aware parsing and range-error handling. |
Review effort: Balanced
|
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.



Fixes WW-5814
Problem
DateConverteraccepts ISO date-times ending inZforjava.util.Dateproperties (since WW-5813 through explicit'Z'-literal formats), but treats theZas a literal.2026-10-25T05:14:42.000Z, the form JavaScript'sDate.toISOString()produces, is read in the server's default time zone, so a UTC timestamp from a client is shifted by the server's offset. Numeric offsets (+02:00) are rejected.Change
Reading
Zas UTC changes the instant every existing...Zvalue converts to, silently and with no conversion error, so it is opt-in:struts.converter.date.isoOffsetAware(StrutsConstants.STRUTS_CONVERTER_DATE_ISO_OFFSET_AWARE), defaultfalseindefault.propertiesfalse: unchanged,Zread as server-local timetrue: ajava.util.Datetarget (andCalendar, which converts through it) first triesDateTimeFormatter.ISO_OFFSET_DATE_TIME:Zmeans UTC.5Zreads as 5 ms, because.SSScounts digits)Date's range is a conversion error instead of an escapingIllegalArgumentExceptionThe default flips to
truein 8.0.0: WW-5815.Out of scope:
java.sql.Timestamp, which has no ISO support todayjava.timetypes:OffsetDateTimealready parses offsets, and theLocal*types have no zoneTests
DateConverter.initDispatcherturns the reading on.Zwith and without milliseconds is read as UTC+02:00is honoured.5reads as half a secondZtests pinAsia/Tokyoas the default zone and restore it intearDown, so they cannot pass vacuously on a UTC build machine.Docs
🤖 Generated with Claude Code