Hikarikun92 opened a new issue, #1366:
URL: https://github.com/apache/logging-log4j2/issues/1366
## Description
When I have an instance of a `java.sql.Date` object and try to log it as a
parameterized message, the newest version of Log4J assumes it's a regular
`java.util.Date` one and tries to call `Date.toInstant()` when logging it. This
works for `java.util.Date` and its subclasses `java.sql.Timestamp` and
`java.sql.Time` (which uses a specific format for that type), but fails for
`java.sql.Date`, as it throws an `UnsupportedOperationException`.
## Configuration
**Version:** 2.20.0
## Logs
```
ERROR StatusConsoleListener An exception occurred processing Appender Console
java.lang.UnsupportedOperationException
at java.sql/java.sql.Date.toInstant(Date.java:316)
at
org.apache.logging.log4j.message.ParameterFormatter.appendDate(ParameterFormatter.java:492)
at
org.apache.logging.log4j.message.ParameterFormatter.appendSpecialTypes(ParameterFormatter.java:485)
at
org.apache.logging.log4j.message.ParameterFormatter.recursiveDeepToString(ParameterFormatter.java:474)
at
org.apache.logging.log4j.message.ParameterFormatter.recursiveDeepToString(ParameterFormatter.java:449)
at
org.apache.logging.log4j.message.ParameterFormatter.formatMessage2(ParameterFormatter.java:192)
at
org.apache.logging.log4j.message.ParameterizedMessage.formatTo(ParameterizedMessage.java:227)
at (...)
at
org.apache.logging.log4j.spi.AbstractLogger.info(AbstractLogger.java:1407)
at com.example.Log4JTest.test(Log4JTest.java:13)
at (...)
```
## Reproduction
log4j2.xml:
```
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="%d{MM-dd HH:mm:ss.SSS} %5p %c:
%m%n%ex"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
```
JUnit test:
```
public class Log4JTest {
@Test
void test() {
Logger logger = LogManager.getLogger();
logger.info("Test: {}", java.sql.Date.valueOf(LocalDate.now()));
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]