Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8045734 | 8u25 | Xueming Shen | P3 | Resolved | Fixed | b01 |
JDK-8041360 | 8u20 | Xueming Shen | P3 | Resolved | Fixed | b13 |
JDK-8053563 | emb-8u26 | Xueming Shen | P3 | Resolved | Fixed | b17 |
FULL PRODUCT VERSION :
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b123)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b65, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.3.9600]
A DESCRIPTION OF THE PROBLEM :
The javadoc of the method java.time.format.DateTimeFormatter::withZone says: "If no zone has been parsed, then this override zone will be included in the result of the parse where it can be used to build instants and date-times." However, the implementation doesn't obey this.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss").withZone(ZoneOffset.UTC);
TemporalAccessor acc = fmt.parse("01/08/2012 00:00:01");
ZonedDateTime zdt = ZonedDateTime.from(acc);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code runs without throwing an exception.
ACTUAL -
An exception is thrown.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.time.DateTimeException: Unable to obtain ZonedDateTime from TemporalAccessor: {},ISO resolved to 2012-08-01T00:00:01 of type java.time.format.Parsed
at java.time.ZonedDateTime.from(ZonedDateTime.java:564)
at Jsr310Bug.main(Jsr310Bug.java:11)
Caused by: java.time.DateTimeException: Unable to obtain ZoneId from TemporalAccessor: {},ISO resolved to 2012-08-01T00:00:01 of type java.time.format.Parsed
at java.time.ZoneId.from(ZoneId.java:466)
at java.time.ZonedDateTime.from(ZonedDateTime.java:552)
... 1 more
Java Result: 1
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
public class Jsr310Bug {
public static void main(String[] args) {
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss").withZone(ZoneOffset.UTC);
TemporalAccessor acc = fmt.parse("01/08/2012 00:00:01");
ZonedDateTime zdt = ZonedDateTime.from(acc);
}
}
---------- END SOURCE ----------
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b123)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b65, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.3.9600]
A DESCRIPTION OF THE PROBLEM :
The javadoc of the method java.time.format.DateTimeFormatter::withZone says: "If no zone has been parsed, then this override zone will be included in the result of the parse where it can be used to build instants and date-times." However, the implementation doesn't obey this.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss").withZone(ZoneOffset.UTC);
TemporalAccessor acc = fmt.parse("01/08/2012 00:00:01");
ZonedDateTime zdt = ZonedDateTime.from(acc);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code runs without throwing an exception.
ACTUAL -
An exception is thrown.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.time.DateTimeException: Unable to obtain ZonedDateTime from TemporalAccessor: {},ISO resolved to 2012-08-01T00:00:01 of type java.time.format.Parsed
at java.time.ZonedDateTime.from(ZonedDateTime.java:564)
at Jsr310Bug.main(Jsr310Bug.java:11)
Caused by: java.time.DateTimeException: Unable to obtain ZoneId from TemporalAccessor: {},ISO resolved to 2012-08-01T00:00:01 of type java.time.format.Parsed
at java.time.ZoneId.from(ZoneId.java:466)
at java.time.ZonedDateTime.from(ZonedDateTime.java:552)
... 1 more
Java Result: 1
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
public class Jsr310Bug {
public static void main(String[] args) {
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss").withZone(ZoneOffset.UTC);
TemporalAccessor acc = fmt.parse("01/08/2012 00:00:01");
ZonedDateTime zdt = ZonedDateTime.from(acc);
}
}
---------- END SOURCE ----------
- backported by
-
JDK-8041360 java.time.format.DateTimeFormatter doesn't set zone when parsing
-
- Resolved
-
-
JDK-8045734 java.time.format.DateTimeFormatter doesn't set zone when parsing
-
- Resolved
-
-
JDK-8053563 java.time.format.DateTimeFormatter doesn't set zone when parsing
-
- Resolved
-
- duplicates
-
JDK-8033659 parsing java.time.Instant without a zoneId may be broken
-
- Closed
-