IBMStreams / streamsx.json

Toolkit for working with JSON in SPL applications.
http://ibmstreams.github.io/streamsx.json/
Other
3 stars 19 forks source link

Invalid Number Exception when parsing number 0E-10 #29

Closed danlopezv closed 9 years ago

danlopezv commented 9 years ago

Whenever the json object contains an element with value = 0E-10 the method processing the number throws an exception. The problem is in the JSON4J library, Tokenizer class, readNumber() method. I ran a test using the Tokenizer class directly:

try {
    String str = "{\"TEST\"0E-10}";
    StringReader str_read = new StringReader(str);
    Tokenizer tkn = new Tokenizer(str_read);
    Token t;

    do
    {
        t = tkn.next();
        System.out.println(t.toString());
    }
    while(t!=Token.TokenEOF);

} catch (IOException e) {
    e.printStackTrace();
}

and this is the error I got:

Token: {
Token: String - 'TEST'
java.io.IOException: Invalid number literal on line 1, column 8
    at com.ibm.json.java.internal.Tokenizer.readNumber(Tokenizer.java:308)
    at com.ibm.json.java.internal.Tokenizer.next(Tokenizer.java:114)
    at Main.main(Main.java:23)
Caused by: java.lang.NumberFormatException: For input string: "E-10"
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Long.parseLong(Unknown Source)
    at java.lang.Long.valueOf(Unknown Source)
    at com.ibm.json.java.internal.Tokenizer.readNumber(Tokenizer.java:290)
    ... 2 more

However, if the value is 0.0E-10 everything works fine:

Token: {
Token: String - 'TEST'
Token: Number - 0.0
Token: }
Token: EOF

or the value is 2E-10:

Token: {
Token: String - 'TEST'
Token: Number - 2.0E-10
Token: }
Token: EOF
rohitsw commented 9 years ago

Unfortunately that library is not part of this repository and is being linked with at runtime. Not much we can do about it here. I recommend using a string type to extract such attributes and then using a custom function to convert to appropriate numeric value, as a workaround.

danlopezv commented 9 years ago

My intention was to point out the issue so it can be fixed on a future release. I know the library is not part of this repository but it's still an IBM implementation and it's the heart and soul of this toolkit. Any suggestion where I can submit this issue? Thanks.