All,
I'm a little unsure of how to back-port this.
First, it uses switch(Object) which isn't available until Java 17, but
that's easily fixed.
Second, Jakarta 11 requires support for java.time types but the Tomcat
11.0.x branch doesn't seem to contain the coerseToInstant method that is
in main. Is that an oversight? Merely "fixing" the patch won't actually
make it work, since coerceToInstant and its use is simply missing.
Third, I see no reason NOT to support Instant in Tomcat versions older
than 11. While neither pre-11 Jakarta EL nor Java EL require support, I
think it might be good to support it, anyway.
So I think I'm looking for validation on the above plan: add Instant
support to Tomcat 11.0.x and then go ahead and back-port it to Tomcat
10.1.x and 9.0.x.
Thanks,
-chris
On 8/12/26 9:32 PM, lihongyi87 (via GitHub) wrote:
lihongyi87 opened a new pull request, #1040:
URL: https://github.com/apache/tomcat/pull/1040
## Problem
Coercion to `java.time.Instant` (added for Tomcat 12) can leak unchecked exceptions instead of the `ELException` required by the EL specification.
In `ELSupport.coerceToInstant()`:
- `Instant.parse("not-a-date")` throws `java.time.format.DateTimeParseException`
- `Instant.from(LocalDate.of(...))` throws `java.time.DateTimeException` /
`UnsupportedTemporalTypeException`
Both are `RuntimeException` subclasses that propagate directly to the caller, while the method contract (and the rest of `ELSupport`, e.g. `coerceToNumber`) requires a `jakarta.el.ELException`.
## Fix
Wrap the failures from `Instant.from()` and `Instant.parse()` in `ELException`, matching the pattern already used by `coerceToNumber` for `NumberFormatException`.
## Testing
Added three tests to `TestELSupport`:
- `testCoerceToInstant01` — valid string coerces to `Instant`
- `testCoerceToInstant02` — invalid string throws `ELException`
- `testCoerceToInstant03` — `LocalDate` (no timezone) throws `ELException`
`TestELSupport` passes (54 tests, 0 failures) on JDK 23.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]