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

Bug in DataClassCodec's getCodec Method with Optional Generic Type Fields

    • Java Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      Bug in DataClassCodec's getCodec Method with Optional Generic Type Fields

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

      5.0

       

      I have encountered a bug within the DataClassCodec implementation of the bson-kotlin library, specifically in the getCodec function. The issue arises when attempting to retrieve type argument information using the typeMap. The bug manifests when a field's type is an optional generic type, leading to a mismatch in the typeMap key.

      Upon closer inspection, I found that the existing mechanism for matching the type arguments fails to account for optional generic types adequately, resulting in incorrect or failed codec retrieval. By modifying the matching process to use the type's classifier instead of directly querying the typeMap, the codec resolution process functions correctly, even with optional generic types.

      I propose to update the matching logic in the getCodec method to utilize the type's classifier for matching, which has been tested and verified to work as expected. This change addresses the bug by ensuring that type arguments are correctly identified and matched, including those of optional generic types.

      I am in the process of finalizing these modifications and will be submitting a pull request (PR) with the proposed changes. I believe this fix will enhance the library's robustness, particularly in handling complex data models that include optional generic types.

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            ht.jo@navercorp.com Hyeontae Jo
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: