Copilot commented on code in PR #406:
URL: https://github.com/apache/commons-net/pull/406#discussion_r3665197398


##########
src/test/java/org/apache/commons/net/ftp/parser/MLSxEntryParserTest.java:
##########
@@ -68,6 +75,25 @@ protected FTPFile nullFileOrNullDate(final FTPFile f) {
         return f;
     }
 
+    /**
+     * The RFC 3659 time stamp is a numeric Gregorian date. Parsing it must 
not depend on the JVM default locale's calendar, which for e.g. a Thai locale 
is a
+     * Buddhist calendar that would read the year 543 years out.
+     */
+    @Test
+    void testParseGMTdateTimeWithNonGregorianDefaultLocale() {
+        final Locale defaultLocale = Locale.getDefault();
+        try {
+            Locale.setDefault(new Locale("th", "TH"));
+            final Calendar parsed = 
MLSxEntryParser.parseGMTdateTime("20100313224553");

Review Comment:
   These tests mutate the JVM-wide default locale, which can make the test 
suite flaky if JUnit is configured to run tests in parallel (or if other tests 
rely on the default locale concurrently). Consider guarding the mutation with 
JUnit 5 parallel-execution controls (e.g., a resource lock for system-wide 
settings / same-thread execution) and/or limiting the blast radius by using 
`Locale.setDefault(Locale.Category.FORMAT, ...)` with matching save/restore via 
`Locale.getDefault(Locale.Category.FORMAT)`.



##########
src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java:
##########
@@ -294,6 +295,7 @@ public Calendar parseTimestamp(final String timestampStr, 
final Calendar serverT
             final String year = Integer.toString(now.get(Calendar.YEAR));
             final String timeStampStrPlusYear = timestampStr + " " + year;
             final SimpleDateFormat hackFormatter = new 
SimpleDateFormat(recentDateFormat.toPattern() + " yyyy", 
recentDateFormat.getDateFormatSymbols());
+            hackFormatter.setCalendar(new GregorianCalendar());

Review Comment:
   `year` is derived from `now.get(Calendar.YEAR)`, where `now` is (based on 
typical usage) ultimately sourced from the `serverTime` calendar passed into 
`parseTimestamp`. If the caller constructed `serverTime` via 
`Calendar.getInstance(...)` under a non-Gregorian default locale, `now` may be 
a `BuddhistCalendar`, so `YEAR` will be the Buddhist year and will still shift 
parsing by +543 even though the formatter calendar is Gregorian. To fully 
decouple parsing from the ambient locale, compute the appended year using a 
`GregorianCalendar` (with the same instant/timezone as `serverTime`) before 
building `timeStampStrPlusYear`.



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