This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 6daf7a7b50 Follow-up to a59c714933
6daf7a7b50 is described below
commit 6daf7a7b50680dcc61577e01aa72af6e4370966f
Author: Mark Thomas <[email protected]>
AuthorDate: Fri Aug 14 09:15:03 2026 +0100
Follow-up to a59c714933
- reduce code duplication
- both Clock and Date can also throw (see java.sql.Date)
---
java/org/apache/el/lang/ELSupport.java | 37 +++++++++++-------------------
test/org/apache/el/lang/TestELSupport.java | 7 ++++++
2 files changed, 21 insertions(+), 23 deletions(-)
diff --git a/java/org/apache/el/lang/ELSupport.java b/java/org/apache/el/lang/ELSupport.java
index 48ee4952bb..20665e002d 100644
--- a/java/org/apache/el/lang/ELSupport.java
+++ b/java/org/apache/el/lang/ELSupport.java
@@ -550,31 +550,22 @@ public class ELSupport {
}
}
- return switch (obj) {
- case null -> null;
- case TemporalAccessor t -> {
- try {
- yield Instant.from(t);
- } catch (DateTimeException e) {
- throw new ELException(
- MessageFactory.get("error.convert", obj, obj.getClass().getName(), Instant.class), e);
- }
- }
- case Clock c -> c.instant();
- case Date d -> d.toInstant();
- case String s -> {
- try {
- yield Instant.parse(s);
- } catch (DateTimeException e) {
+ try {
+ return switch (obj) {
+ case null -> null;
+ case TemporalAccessor t -> Instant.from(t);
+ case Clock c -> c.instant();
+ case Date d -> d.toInstant();
+ case String s -> Instant.parse(s);
+ default -> {
throw new ELException(
- MessageFactory.get("error.convert", obj, obj.getClass().getName(), Instant.class), e);
+ MessageFactory.get("error.convert", obj, obj.getClass().getName(), Instant.class));
}
- }
- default -> {
- throw new ELException(
- MessageFactory.get("error.convert", obj, obj.getClass().getName(), Instant.class));
- }
- };
+ };
+ } catch (DateTimeException | UnsupportedOperationException e) {
+ throw new ELException(
+ MessageFactory.get("error.convert", obj, obj.getClass().getName(), Instant.class), e);
+ }
}
/**
diff --git a/test/org/apache/el/lang/TestELSupport.java b/test/org/apache/el/lang/TestELSupport.java
index 11ff702552..9042e6cb02 100644
--- a/test/org/apache/el/lang/TestELSupport.java
+++ b/test/org/apache/el/lang/TestELSupport.java
@@ -19,6 +19,7 @@ package org.apache.el.lang;
import java.beans.PropertyEditorManager;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.sql.Date;
import java.time.Instant;
import java.time.LocalDate;
import java.util.Map;
@@ -256,6 +257,12 @@ public class TestELSupport {
ELSupport.coerceToType(null, LocalDate.of(2024, 1, 1), Instant.class);
}
+ @Test(expected = ELException.class)
+ public void testCoerceToInstant04() {
+ // java.sql.Date can't convert to Instant
+ ELSupport.coerceToType(null, new Date(0), Instant.class);
+ }
+
@Test
public void testCoerceToNumber01() {
Object result = ELSupport.coerceToNumber(null, null, Integer.class);
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.