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

NPE with getter without backing field

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.8.2
    • Affects Version/s: 3.7.0, 3.7.1, 3.8.0, 3.8.1
    • Component/s: POJO
    • None
    • Fully Compatible

      ConventionSetPrivateFieldImpl throws a NPE when mapping a POJO with a getter method. This getter isn't related to a backing field, it is simply a business getter (like getTotal() of a sale).

      The relevant part of stacktrace is:

       

      java.lang.NullPointerException: nulljava.lang.NullPointerException: null at org.bson.codecs.pojo.ConventionSetPrivateFieldImpl.apply(ConventionSetPrivateFieldImpl.java:36) at org.bson.codecs.pojo.ClassModelBuilder.build(ClassModelBuilder.java:252) at org.bson.codecs.pojo.PojoCodecProvider.createClassModel(PojoCodecProvider.java:214) at org.bson.codecs.pojo.PojoCodecProvider.getPojoCodec(PojoCodecProvider.java:78) at org.bson.codecs.pojo.PojoCodecProvider.get(PojoCodecProvider.java:68) at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:43) at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:55) at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37) at com.mongodb.internal.operation.Operations.createFindOperation(Operations.java:144) at com.mongodb.internal.operation.Operations.findFirst(Operations.java:128) at com.mongodb.internal.operation.AsyncOperations.findFirst(AsyncOperations.java:81) at com.mongodb.async.client.FindIterableImpl.first(FindIterableImpl.java:197)

       

       

      Debugging to discover the NPE source i'm got to this point of failure at line 36 of bson/src/main/org/bson/codecs/pojo/ConventionSetPrivateFieldImpl.java:

       

      if (!propertyMetaData.isDeserializable() && isPrivate(propertyMetaData.getField().getModifiers()))
      

      When the propertyMetaData has state:

      setter=null
      field=null
      getter=not null

      The return of isDeserializable is false, then after ! the other condition of && is tested, in this the propertyMetadaData.getField() that is null, is acessed without nullable check.

       

       

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            eprecise-clecius Clécius J. Martinkoski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: