More number parsing improvements.

This commit is contained in:
Jesse Wilson 2012-08-27 03:17:41 +00:00
parent 448063dde1
commit b0a172944a
2 changed files with 17 additions and 1 deletions

View File

@ -658,7 +658,7 @@ public class JsonReader implements Closeable {
}
if (c == -1 || !isLiteral((char) c)) {
if (fitsInLong) {
if (fitsInLong && (integer != Long.MIN_VALUE || negative)) {
peekedInteger = negative ? integer : -integer;
pos += i;
return peeked = PEEKED_INTEGER;

View File

@ -454,6 +454,22 @@ public final class JsonReaderTest extends TestCase {
}
}
/**
* This test fails because there's no double for 9223372036854775808, and our
* long parsing uses Double.parseDouble() for fractional values.
*/
public void testPeekLargerThanLongMaxValue() throws IOException {
JsonReader reader = new JsonReader(new StringReader("[9223372036854775808]"));
reader.setLenient(true);
reader.beginArray();
assertEquals(NUMBER, reader.peek());
try {
reader.nextLong();
fail();
} catch (NumberFormatException e) {
}
}
/**
* This test fails because there's no double for -9223372036854775809, and our
* long parsing uses Double.parseDouble() for fractional values.