Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2702

BasicDBObject.parse fails to parse json if it contains big numbers

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.4.3, 3.6.0
    • Component/s: JSON
    • Labels:
      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)
      

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            danilov.m.u@gmail.com Mikhail Danilov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: