Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

What the heck - date parsing error using SimpleDateFormat - why?

361137Feb 16 2012 — edited Feb 17 2012
I have the following code:

public long parseDate (String date) {

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");

try {
return sdf.parse(date).getTime();
}
catch (Exception e) {
throw new Exception("Error parsing date: "+date, e);
}
}

It seemed to work fine when I ran it but when someone who I deployed the code to ran it they get an error:

Error parsing date: 20120201000000

And then oddly in the stack trace it says:
Caused by: java.lang.NumberFormatException: For input string: ".E0"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at java.text.DigitList.getDouble(Unknown Source)
at java.text.DecimalFormat.parse(Unknown Source)
at java.text.SimpleDateFormat.subParse(Unknown Source)
at java.text.SimpleDateFormat.parse(Unknown Source)
at java.text.DateFormat.parse(Unknown Source)

This does not make any sense to me. Where is it seeing the input string ".E0" ???

The variable "date" is not shared anywhere - in fact this parseDate method is the only method in the entire class, but anyway it is a local scope variable. Same goes for sdf. So it cannot be some other thread unexpectedly changing the state of the objects I am using... This situation has me perplexed.

Their environment is Java 1.6.0_26 on Win7 box

Edited by: trant on Feb 16, 2012 7:12 AM

Edited by: trant on Feb 16, 2012 7:13 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 16 2012
Added on Feb 16 2012
6 comments
2,273 views