kgregory-chariot commented on issue #1476:
URL: 
https://github.com/apache/logging-log4j2/issues/1476#issuecomment-1840866672

   @ppkarwasz - I believe that #1366 referenced a different issue -- or 
`ParameterFormatter.appendDate()` is dead code and should be removed.
   
   This is the [current mainline 
code](https://github.com/apache/logging-log4j2/blob/2.x/log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java#L434C28-L434C38):
   
   ```
       private static boolean appendDate(final Object o, final StringBuilder 
str) {
           if (!(o instanceof Date)) {
               return false;
           }
           str.append(DATE_FORMATTER.format(((Date) o).toInstant()));
           return true;
       }
   ```
   
   If you pass an instance of `java.sql.Date` (or `java.sql.Time`) to this 
function, it will throw `UnsupportedOperationException` [per 
documentation](https://docs.oracle.com/en/java/javase/21/docs/api/java.sql/java/sql/Date.html#toInstant()).
   
   To properly handle the `java.sql` types, you could either add some more 
instance-of tests to perform valid conversions, or do the following:
   
   ```
   str.append(DATE_FORMATTER.format(Instant.ofEpochMilli(((Date) 
o).getTime())));
   ```
   
   I actually think that the additional instance-of tests would be better, 
using the built-in string conversion, because treating a SQL date or time as a 
timestamp will be confusing.


-- 
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]

Reply via email to