FULL PRODUCT VERSION :
A DESCRIPTION OF THE PROBLEM :
Both "2016-09-12T16:45:51+00:00" and "2016-09-12T16:45:51Z" are valid ISO-8601 representations of java.time.Instant. However, Instant.parse() will only parse the latter, but not the former.
The problem actually lies in java.time.format.DateTimeFormatter.ISO_INSTANT. According to the documentation (http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_INSTANT), it inherits from DateTimeFormatter.ISO_OFFSET_DATE_TIME. However, the documentation is incorrect and that is not the way it was implemented.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Instant instant = Instant.parse("2016-09-12T16:45:51+00:00");
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exceptions thrown, with instant properly initialized.
ACTUAL -
java.time.format.DateTimeParseException: Text '2016-09-12T16:45:51+00:00' could not be parsed at index 19
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.time.format.DateTimeParseException: Text '2016-09-12T16:45:51+00:00' could not be parsed at index 19
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.time.Instant;
import org.junit.Assert;
import org.junit.Test;
public class MyTest {
@Test
public void test() {
Instant instant1 = Instant.parse("2016-09-12T16:45:51+00:00");
Instant instant2 = Instant.parse("2016-09-12T16:45:51Z");
Assert.assertEquals(instant2, instant1);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
DateTimeFormatter.ISO_OFFSET_DATE_TIME can be used directly to create the Instant.
This is not always practical for all use cases (such as where Instant is being unmarshalled using a third-party library).
A DESCRIPTION OF THE PROBLEM :
Both "2016-09-12T16:45:51+00:00" and "2016-09-12T16:45:51Z" are valid ISO-8601 representations of java.time.Instant. However, Instant.parse() will only parse the latter, but not the former.
The problem actually lies in java.time.format.DateTimeFormatter.ISO_INSTANT. According to the documentation (http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_INSTANT), it inherits from DateTimeFormatter.ISO_OFFSET_DATE_TIME. However, the documentation is incorrect and that is not the way it was implemented.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Instant instant = Instant.parse("2016-09-12T16:45:51+00:00");
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exceptions thrown, with instant properly initialized.
ACTUAL -
java.time.format.DateTimeParseException: Text '2016-09-12T16:45:51+00:00' could not be parsed at index 19
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.time.format.DateTimeParseException: Text '2016-09-12T16:45:51+00:00' could not be parsed at index 19
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.time.Instant;
import org.junit.Assert;
import org.junit.Test;
public class MyTest {
@Test
public void test() {
Instant instant1 = Instant.parse("2016-09-12T16:45:51+00:00");
Instant instant2 = Instant.parse("2016-09-12T16:45:51Z");
Assert.assertEquals(instant2, instant1);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
DateTimeFormatter.ISO_OFFSET_DATE_TIME can be used directly to create the Instant.
This is not always practical for all use cases (such as where Instant is being unmarshalled using a third-party library).
- csr for
-
JDK-8211316 DateTimeFormatterBuilder's appendInstant() method should parse any offset provided in the input
- Closed