-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Minor - P4
-
None
-
Affects Version/s: 3.4.3, 3.6.0
-
Component/s: JSON
-
None
Input:
JSON with big number (exceeds java.lang.Long limits).
Sample code:
BasicDBObject obj = BasicDBObject.parse("{\"bigNum\": 11111111111111111111111}"); System.out.println(obj);
Expected behavior:
BasicDBObject.parse handles such number as Decimal128 (added in 3.4)
Actual behavior:
BasicDBObject.parse fails with NumberFormatException. (JsonScanner.scanNumber tries to parse number as Integer, Long or Double, but not Decimal128).
Exception in thread "main" java.lang.NumberFormatException: For input string: "11111111111111111111111" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Long.parseLong(Long.java:592) at java.lang.Long.parseLong(Long.java:631) at org.bson.json.JsonScanner.scanNumber(JsonScanner.java:437) at org.bson.json.JsonScanner.nextToken(JsonScanner.java:93) at org.bson.json.JsonReader.popToken(JsonReader.java:492) at org.bson.json.JsonReader.readBsonType(JsonReader.java:136) at com.mongodb.DBObjectCodec.readDocument(DBObjectCodec.java:345) at com.mongodb.DBObjectCodec.decode(DBObjectCodec.java:138) at com.mongodb.DBObjectCodec.decode(DBObjectCodec.java:61) at com.mongodb.BasicDBObject.parse(BasicDBObject.java:74) at com.mongodb.BasicDBObject.parse(BasicDBObject.java:61)