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

ClassModel throws ClassCastException when deep ParameterizedType exist in field type

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: POJO
    • None
    • Java Drivers

      Summary

      ClassModel.builder has a problem when a class contains fields that have nested parametrized types. The only solution I found was to loose the types, e.g by using raw types or avoid extends.

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      Tested on 4.8.2, 5.1.4, 5.2.0

      How to Reproduce

       

      package org.example;
      
      import java.util.List;
      import org.bson.codecs.pojo.ClassModel;
      
      class Counter<T extends Number> {}
      
      class Person<T extends Counter<?>> {
          public T counter;
      }
      
      class Pojo1 {
          public List<? extends Person<? extends Counter<?>>> persons;
      }
      
      class Pojo2 {
          public List<Person<? extends Counter<?>>> persons;
      }
      
      class Pojo3 {
          public List<Person<?>> persons;
      }
      
      class Pojo4 {
          public List<Person<? extends Counter>> persons;
      }
      
      class Pojo5 {
          public List<? extends Person> persons;
      }
      
      class Pojo6 {
          public List<? extends Person<?>> persons;
      }
      
      public class Main {
      
          public static void main(String[] args) {
              ClassModel.builder(Pojo1.class); // throws
              ClassModel.builder(Pojo2.class); // throws
              ClassModel.builder(Pojo3.class); // ok
              ClassModel.builder(Pojo4.class); // ok
              ClassModel.builder(Pojo5.class); // ok
              ClassModel.builder(Pojo6.class); // throws
          }
      
      }
      

       

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            bragon912@gmail.com Patryk Szafran
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: