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

Pojo with method returning an Enum - NPE / "Can't find a codec for class"

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.1
    • Affects Version/s: 3.6.0
    • Component/s: POJO
    • Labels:
      None

      Using Enums with the PojoCodecProvider.Builder.automatic(true) causes a NPE.

      Was
      ======

      Hi again,
      I'm trying to use java mongo drive 3.6 to save pojo's in db.
      However, if my pojo contains method:

      @BsonIgnore
      public MyEnum getSomeValue() { ... compute and return value... }
      

      I get NullPointerException in PojoCodecImpl:shouldSpecialize (:332)
      In typeParameterMap there is: "cachedConstructor" : "0=0"
      but when the code looks for the "cachedConstructor" in classModel.getPropertyModel ,it finds nothing. So classModel.getPropertyModel((String)entry.getKey()).getCodec() ends in NPE.

      If I change the name of the metod (so that it is not mistaken with a getter):

      @BsonIgnore
      public MyEnum someValue() { ... compute and return value... }
      

      I get a
      Error: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class

      If I remove this method from my pojo, everything works fine.
      In general I assume I can have multiple methods that are not getters and setters - and that they will not interfere with saving the pojo. I have added @BsonIgnore to be sure - but it seems that this method is not ignored.

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            aneta stępień aneta stępień
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: