Regression negative number from Lenient
antoinetran opened this issue · comments
Since the merge of #137, there is a regression. json-io version: 4.11.1
I made a simple UT, that reads "-1234". It shows
com.cedarsoftware.util.io.JsonIoException: Invalid number: --234
line: 1, col: 28
}{"@type":"int","value":--234
at com.cedarsoftware.util.io.JsonParser.error(JsonParser.java:528)
at com.cedarsoftware.util.io.JsonParser.readNumber(JsonParser.java:368)
at com.cedarsoftware.util.io.JsonParser.readValue(JsonParser.java:545)
...
Caused by: java.lang.NumberFormatException: For input string: "--234"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.base/java.lang.Long.parseLong(Long.java:692)
at java.base/java.lang.Long.parseLong(Long.java:817)
at com.cedarsoftware.util.io.JsonParser.readNumber(JsonParser.java:363)
... 36 more
Analysis:
In the code, in JsonParser.java:
// Case "-Infinity", "Infinity" or "NaN".
if (c == 'I') {
// [Out of RFC 4627] accept NaN/Infinity values
readToken("infinity");
return (isNeg) ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
} else if ('N' == c) {
// [Out of RFC 4627] accept NaN/Infinity values
readToken("nan");
return Double.NaN;
} else {
// Case this is a number but not "-Infinity", like "-2". We let the normal code process.
input.unread('-');
}
The last line is wrong:
input.unread('-');
should have been input.unread('c'); c = '-';
to reset to the initial state.
Hi @jdereg , sorry my former code brought an error. This should fixes it, I reproduced the error in a new UT and checked that it is fixed.
Now I made a pull request but I saw Travis error, that has nothing to do with this issue: Jdk8 couldn't be installed (source here)
Expected feature release number in range of 9 to 14, but got: 8
The command "~/bin/install-jdk.sh --target "/home/travis/oraclejdk8" --workspace "/home/travis/.cache/install-jdk" --feature "8" --license "BCL"" failed and exited with 3 during .
It seems Travis want to use Jdk8 but one restricted it from 9 to 14.
Pull request here: #145