Details
Description
Some of the unit tests related to DateTimeFormatter were failing in Java versions greater than 8 while working in Java 8.
Example of a failing Unit Test : org.apache.hadoop.hive.common.type.TestTimestampTZ#testComparision
java.time.format.DateTimeParseException: Text '2017-04-14 18:00:00 UTC+08:00' could not be parsed, unparsed text found at index 23 at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2049) at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1874) at org.apache.hadoop.hive.common.type.TimestampTZUtil.parse(TimestampTZUtil.java:76) at org.apache.hadoop.hive.common.type.TimestampTZUtil.parse(TimestampTZUtil.java:64) at org.apache.hadoop.hive.common.type.TestTimestampTZ.testComparison(TestTimestampTZ.java:44) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
The appendZoneText(TextStyle) method of DateTimeFormatteBuilder is not able to parse the + symbol in 2017-04-14 18:00:00 UTC+08:00 when running the test in Java 11 , while it is working fine with Java 8.
According to the doc , appendZoneText(TextStyle) should be able to parse either the textual zone name, the zone ID or the offset and UTC+08:00 should come under offset as per the same doc.
It seems, however, that "UTC" was explicitly removed when parsed as ZoneText for higher Java versions
As a workaround, we can use appendZoneOrOffsetId() rather than appendZoneText().
This ensures the tests are passing for Java 8+ and based on my testing, I didn’t see any regression of the change.
Sample repro code - jdoodle.com/ia/D5e
Attachments
Attachments
Issue Links
- links to