Mailing List Archive

DO NOT REPLY [Bug 14485] New: - Lucene 1.3dev1-2002-10-27 : NumberFormat Exception while parsing Date by DateField.stringToTime(String s) method
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14485>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14485

Lucene 1.3dev1-2002-10-27 : NumberFormat Exception while parsing Date by DateField.stringToTime(String s) method

Summary: Lucene 1.3dev1-2002-10-27 : NumberFormat Exception while
parsing Date by DateField.stringToTime(String s) method
Product: Lucene
Version: CVS Nightly - Specify date in submission
Platform: Other
OS/Version: Other
Status: NEW
Severity: Normal
Priority: Other
Component: Other
AssignedTo: lucene-dev@jakarta.apache.org
ReportedBy: max@osua.de


This bug appears on my system with the lataest nightly build 2002-10-27.

I've got NumberFormat
Exception when trying to parse back string representetion of date to Java long
type:

java.lang.NumberFormatException: d8ae40fe
at
java.lang.Long.parseLong(Unknown Source)
at
org.apache.lucene.document.DateField.stringToTime(Unknown Source)

I guess the
reason is the following portion of code in the timeToString method of
org.apache.lucene.document.DateField class (lines 111-112):

...
while (sb.length() <
DATE_LEN)
sb.insert(0, ' '); // inserts leading spaces
s = sb.toString();
}

return
s;
}
So, it appears, that the value, returned by the method, may contain leading spaces, and
thus, back conversion by Long.parseLong method brings NimberFormatException.

I changed
the code of the stringToTime method to trim the string before the parsing and it fixes the
problem:

public static long stringToTime(String s) {
return Long.parseLong(s.trim(),
Character.MAX_RADIX);
}

--
To unsubscribe, e-mail: <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>