org.bson.codecs.IterableCodec throws NPE when decoding ARRAYs

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • 3.5.0
    • Affects Version/s: 3.4.0
    • Component/s: Codecs
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Assuming you have a structure like the following within mongo db and try to decode it manually, not using org.bson.codecs.DocumentCodec a NullPointerException is being thrown if you trty to decode a nested ARRAY structure.

      database-object:

      { "_id" : ObjectId("585d002202ef6c0c985cd350"), "listOfList" : [ [ ] ] }

      Stacktrace:

      java.lang.NullPointerException
      	at org.bson.codecs.IterableCodec.readValue(IterableCodec.java:118)
      	at org.bson.codecs.IterableCodec.decode(IterableCodec.java:78)
      	at org.bson.codecs.IterableCodec.decode(IterableCodec.java:37)
      

      SampleCode to replay:

              Codec<List> listCodec = mongoClient.getMongoClientOptions().getCodecRegistry().get(List.class);
              List decode = listCodec.decode(new JsonReader("[ [ ] ]"), DecoderContext.builder().build());
      

      Remark:
      If using the org.bson.codecs.DocumentCodec array structures are handled by org.bson.codecs.DocumentCodec itself, so there the problem does not exist.

      I am not 100% sure tht IterableCodec should be able to handle Arrays, I just saw the comments in org.bson.codecs.BsonTypeClassMap stating that ARRAYS are supported. Unfortunately there is no mapping in th defaults section.

              Assignee:
              Jeffrey Yemin
              Reporter:
              Michael Weber
              None
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: