I wanted to parse some date, and for whatever the reason, parsing the date throws an error. I am using IntelliJ to debug it and from what I see, either IntelliJ is showing me a different stack, or something is happening beyond my understanding. I am using jdk 1.8.0_261
in my local, and I am debugging a remote machine which has jdk 1.8.0_291
EDIT: One thing to mention, this bug does not happen all the time. I am using the same and different values for dates and from time to time, it throws an exception. So, although I give "15/04/2021" for an input string, it is not 100% guaranteed that I will face an exception.
This is the thing that I wanted to parse:
return sf.parse((String)properties.get("validfrom"));
sf is SimpleDateFormat
public Date parse(String source) throws ParseException
method is called with the source being "15/04/2021"
DateFormat.java/parse method, line 364
Then, DecimalFormat.java/parse
method, digitList.getLong()
is called. The digitlist seems to have
"0.2021x10^4"
DecimalFormat.java/parse, digitList
Deeper in the stack, Long.parseLong
is called with the same "0.2021x10^4"
Long.getLong() 2 (To capture another picture of the line of codes being executed, I have re-executed from the beginning, that is why the object Id's are different.).
Suddenly, the string passed to parseLong()
becomes ""
static long parseLong(String s)
In the end, it throws an exception.
The weirder thing is, when I try to execute return sf.parse((String)properties.get("validfrom"));
inside debugger mode, with evaluation (pressing alt + clicking on the line) it does not throw an error, and it returns me what I am expecting, the date.
What am I missing in here? Somehow the inner workings of java library between 1.8.0_261 and 291 is changed?
SimpleDateFormat was created via this.sf = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
Stack trace
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:601)
at java.lang.Long.parseLong(Long.java:631)
at java.text.DigitList.getLong(DigitList.java:195)
at java.text.DecimalFormat.parse(DecimalFormat.java:2082)
at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:2162)
at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1514)
at java.text.DateFormat.parse(DateFormat.java:364)
at com.foo.bar(baz.java:123)