Copilot commented on code in PR #433:
URL: https://github.com/apache/commons-beanutils/pull/433#discussion_r3740635772


##########
src/main/java/org/apache/commons/beanutils2/converters/DateTimeConverter.java:
##########
@@ -200,7 +200,7 @@ protected <T> T convertToType(final Class<T> targetType, 
final Object value) thr
             // didn't include the milliseconds. The following code
             // ensures it works consistently across JDK versions
             final java.sql.Timestamp timestamp = (java.sql.Timestamp) value;
-            long timeInMillis = timestamp.getTime() / 1000 * 1000;
+            long timeInMillis = Math.floorDiv(timestamp.getTime(), 1000) * 
1000;
             timeInMillis += timestamp.getNanos() / 1000000;
             return toDate(targetType, timeInMillis);

Review Comment:
   `Math.floorDiv(timestamp.getTime(), 1000) * 1000` can overflow for extreme 
pre-epoch values (e.g., `timestamp.getTime()` in `[Long.MIN_VALUE, 
Long.MIN_VALUE + 999]`), producing a positive millisecond value and breaking 
conversion. The previous truncating expression avoided this overflow. Consider 
keeping floor semantics for representable cases while guarding the `-1000` 
adjustment to avoid underflow near `Long.MIN_VALUE`.



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