You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "garydgregory (via GitHub)" <gi...@apache.org> on 2026/07/28 11:30:26 UTC
Re: [PR] Force gregorian calendar in ftp listing timestamp parsers [commons-net]
garydgregory commented on code in PR #406:
URL: https://github.com/apache/commons-net/pull/406#discussion_r3665106773
##########
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");
+ final GregorianCalendar expected = new GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.ROOT);
+ expected.clear();
+ expected.set(2010, Calendar.MARCH, 13, 22, 45, 53);
+ assertEquals(expected.getTimeInMillis(), parsed.getTimeInMillis());
+ } finally {
+ Locale.setDefault(defaultLocale);
+ }
+ }
+
@Override
@Test
void testDefaultPrecision() {
Review Comment:
Use JUnit Pioneer to set the default Locale: https://junit-pioneer.org/docs/default-locale-timezone/
##########
src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java:
##########
@@ -271,6 +271,32 @@ void testParser() throws ParseException {
}
}
+ /**
+ * A numeric year from a server listing must be read as a Gregorian year regardless of the JVM default locale. Under a Thai locale the default
+ * SimpleDateFormat calendar is a Buddhist calendar, which would otherwise shift the parsed instant by 543 years.
+ */
+ @Test
+ void testParseTimestampWithNonGregorianDefaultLocale() throws ParseException {
+ final Locale defaultLocale = Locale.getDefault();
+ try {
+ Locale.setDefault(new Locale("th", "TH"));
Review Comment:
Use JUnit Pioneer to set the default Locale: https://junit-pioneer.org/docs/default-locale-timezone/
##########
src/test/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParserTest.java:
##########
@@ -156,6 +157,26 @@ void testParseFieldsOnFile() throws Exception {
assertEquals(0, zDateTime.getSecond());
}
+ /**
+ * A numeric year in a listing must be read as a Gregorian year regardless of the JVM default locale. Under a Thai locale the base Calendar is a Buddhist
+ * calendar, which would otherwise store the timestamp 543 years out.
+ */
+ @Test
+ void testAbsoluteYearWithNonGregorianDefaultLocale() {
+ final Locale defaultLocale = Locale.getDefault();
+ try {
+ Locale.setDefault(new Locale("th", "TH"));
Review Comment:
Use JUnit Pioneer to set the default Locale: https://junit-pioneer.org/docs/default-locale-timezone/
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org