SimpleDateFormat.parse returns errorIndex as 0

Using jdk1.7.0_55, I get parseposition.errorIndex as 0 in the timezone case, is not standard.

But using jdk1.6.0_38, I get parseposition.errorIndex as 21 for the same wrong timezone format

The following is an example:

String date = "13 Jan 2005 21:45:34 ABC"; String format = "dd MMM yyyy HH:mm:ss z"; ParsePosition pp = new ParsePosition(0); pp.setIndex(0); SimpleDateFormat sd = new SimpleDateFormat(format,Locale.ENGLISH); Date d = sd.parse(date,pp); System.out.println("Error Index "+pp.getErrorIndex()); 

Result Using jdk 6:

Error Index 21

Result Using jdk 7

Error Index 0

Why is there a difference?

Please, help

+6
source share
1 answer

Indeed, this is a regression. Still broken in the latest version of Java 8. The open OpenJDK error debugger does not list it, so I reported this to Oracle for verification. It is tracked by Oracle with Review ID: JI-9021556

Unfortunately, you cannot fix this.

+2
source

Source: https://habr.com/ru/post/986648/


All Articles