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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

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

Tolls
public class Test {
   public static void main(String[] args) {
      parseDate("20120201000000");
   }

   public static void parseDate(String date) {

      SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");

      try {
         System.out.println(sdf.parse(date).getTime());
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}
That works, 1.6.0_20 on Win7.
Does the above work on yours?
If so then I would question your assumptions about what is going on in your app.
796440
This works fine for me:
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
sdf.parse("20120201000000");
So... evil spirits? Or maybe you're not running the code you think you are? All I can suggest is try it on a different box or with a different version of Java. Or try creating an [url http://sscce.org]SSCCE that reproduces the problem, and then see how it behaves in other environments, or post it here.

From what you've posted, that shouldn't be happening. So either there's a corrupt install or a bug in that version of Java, or there's more to this situation than meets the eye.

Have you tried searching the bug database for this issue?

Edited by: jverd on Feb 16, 2012 10:41 AM
darrylburke
Where is it seeing the input string ".E0" ???
DigitList.java lines 147 to 150

db
gimbal2
Darryl Burke wrote:
Where is it seeing the input string ".E0" ???
DigitList.java lines 147 to 150

db
Your crystal ball is finally back from the shop?
darrylburke
No, the stack trace indicates the program flow. All I had to do was locate the methods in the source files.

db
gimbal2
Darryl Burke wrote:
No, the stack trace indicates the program flow. All I had to do was locate the methods in the source files.

db
I see. You're better/more persistent than I am, I didn't get further than the source of SimpleDateFormat. I saw some caching list of number formats, couldn't really make heads or tails of how it was used and gave up :)
1 - 6
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
1,803 views