Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6234437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:29:08+00:00 2026-05-24T10:29:08+00:00

Edited in accordance with comments For some reason, I seem to be getting this

  • 0

Edited in accordance with comments

For some reason, I seem to be getting this exception randomly occurring when I am trying to parse between Date and String formats in Java.

Here is a snippet of the code I’ve got (this is just for testing purposes):

SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
for(...){
  ...
   System.out.println("Before parsing: [" + lastEntryDate + "]");
   Date date = formatter.parse(lastEntryDate);
   System.out.println("After parsing: [" + date + "]”);
}

And the output:

Before parsing: [Sun Aug 07 22:45:30 EST 2011]
After parsing: [Sun Aug 07 22:45:30 EST 2011]
Before parsing: [Sun Aug 07 22:45:31 EST 2011]
After parsing: [Sun Aug 07 22:45:31 EST 2011]
Before parsing: [Sun Aug 07 22:45:31 EST 2011]
After parsing: [Sun Aug 07 22:45:31 EST 2011]
Before parsing: [Sun Aug 07 22:45:31 EST 2011]
After parsing: [Sun Aug 07 22:45:31 EST 2011]
Before parsing: [Sun Aug 07 22:45:31 EST 2011]
After parsing: [Sun Aug 07 22:45:31 EST 2011]
Before parsing: [Sun Aug 07 22:45:31 EST 2011]
java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    at java.lang.Long.parseLong(Long.java:431)
    at java.lang.Long.parseLong(Long.java:468)
    at java.text.DigitList.getLong(DigitList.java:177)
    at java.text.DecimalFormat.parse(DecimalFormat.java:1298)
    at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1936)
    at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1312)
    at java.text.DateFormat.parse(DateFormat.java:335)
    at proj01.servicebus.ServiceBus.writeFeedEntry(ServiceBus.java:211)
    at proj01.servicebus.ServiceBus.writeFeedEntries(ServiceBus.java:243)
    at proj01.servicebus.ServiceBus.access$1(ServiceBus.java:241)
    at proj01.servicebus.ServiceBus$1.call(ServiceBus.java:84)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)

The problem is:

  • sometimes, the parsing fails ?! (see for example, where it gives 00:00:00)
  • sometimes, the exception shown is thrown ?!
  • the problem seems to be random!

What is the likely cause and solution to this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:29:09+00:00Added an answer on May 24, 2026 at 10:29 am

    It looks like you’re trying to parse an empty string. Therefore the error is in the input data – unfortunately, in that case you won’t display the bad data, as you’re only calling System.out.println once, after parsing.

    If you change your diagnostics to:

    System.out.println("Before parsing: [" + lastEntryDate + "]");
    Date date = formatter.parse(lastEntryDate);
    System.out.println("After parsing: [" + date + "]");
    

    I suspect you’ll see that you get an exception when the data is missing or completely invalid; where it’s parsing to “Sun Aug 07 00:00:00 EST 2011” I suspect you’ll find that the input data really does have that information.

    EDIT: If you’re using multiple threads, you should not be sharing a SimpleDateFormat between the threads. Either create one in each thread or (my preference) use Joda Time instead – it’s a much better library in general, and its formatters are thread-safe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[Edited: After cross-testing on a fresh machine and some additional research, this appears to
edited, this is it function handleDate( timestamp ) { var n=new Date(), t, ago
--- Edited below with some more testing, please read :) --- I'm struggling trying
Edited:- Updated One What's wrong with this code. Now I am getting error on
Edited after getting answers Some excellent answers here. I like Josh's because it is
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
Edited: SOLUTION FOUND. This is strange and not the best solution, but I just
(Edited a lot) I've got some classes with Abstracts Members. The concrete type of
--edited for clarity (hopefully) I have an XML file that looks something like this:
Edited to Add * I haven't found a solution for this one yet, can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.