A DESCRIPTION OF THE PROBLEM :
Using SimpleDateFormatter("yyyy-MM-dd'T'HH:mm:ss'Z'").parse() on a date of "2018-11-330T13:22:36Z" is not only accepted but when decoded to a UTC date becomes "Thu Sep 26 13:22:36 EDT 2019".
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class foo {
public static void main(String[] args) {
String badDate = "2018-11-330T13:22:36Z";
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
try {
System.out.println(format.parse(badDate));
} catch (ParseException ex) {
ex.printStackTrace();
}
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect a ParseException to be thrown when the String badDate didn't match the format.
ACTUAL -
Thu Sep 26 13:22:36 EDT 2019 was returned. It appears Java seems to be adding the extra days onto the date.
---------- BEGIN SOURCE ----------
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class foo {
public static void main(String[] args) {
String badDate = "2018-11-330T13:22:36Z";
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
try {
System.out.println(format.parse(badDate));
} catch (ParseException ex) {
ex.printStackTrace();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Using regex to match the digit characters and then parse the date.
FREQUENCY : always
Using SimpleDateFormatter("yyyy-MM-dd'T'HH:mm:ss'Z'").parse() on a date of "2018-11-330T13:22:36Z" is not only accepted but when decoded to a UTC date becomes "Thu Sep 26 13:22:36 EDT 2019".
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class foo {
public static void main(String[] args) {
String badDate = "2018-11-330T13:22:36Z";
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
try {
System.out.println(format.parse(badDate));
} catch (ParseException ex) {
ex.printStackTrace();
}
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect a ParseException to be thrown when the String badDate didn't match the format.
ACTUAL -
Thu Sep 26 13:22:36 EDT 2019 was returned. It appears Java seems to be adding the extra days onto the date.
---------- BEGIN SOURCE ----------
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class foo {
public static void main(String[] args) {
String badDate = "2018-11-330T13:22:36Z";
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'");
try {
System.out.println(format.parse(badDate));
} catch (ParseException ex) {
ex.printStackTrace();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Using regex to match the digit characters and then parse the date.
FREQUENCY : always