Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-8498

ModuleMap2BeanTransformer does not respect type-mapping

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 6.2.21
    • modulemechanism
    • None

      When extending a module class set in the module's xml descriptor with guice type-mapping, the class is created correctly by ModuleManagerImpl and registered.

      But later in the process of populating the class with actual configuration in yaml or jcr, the Node2Bean mechanism does not use this registered instance and creates new instances instead. This is because of the logic in info.magnolia.config.module.ModuleMap2BeanTransformer#createInstance:

      @Override
          protected Object createInstance(Class<?> type) {
              Object instance;
      
              if (moduleClassToModuleName.containsKey(type.getName())) {
                  instance = moduleRegistry.getModuleInstance(type);
              } else {
                  instance = super.createInstance(type);
              }
              return instance;
          }
      

      The IF-statement fails: the type-mapped class given as parameter is not contained. In moduleClassToModuleName are only those classes defined, which are set in the module's xml descriptors.

      Steps to reproduce

      1.  Create a sub class of an existing module class
      2.  Add a type mapping to your custom module xml descriptor, where the old module class is type mapped to the newly created one.

      We used SsoModule to add custom configuration to org.pac4j.core.config.Config after calling getPac4jConfig().

      Expected results

      Configuration should be applied to the type-mapped instance and should be accessible to functionality using it.

      Actual results

      The configuration is not applied to the instance registered in ModuleRegistry, but instead is applied to other newly created instances not accessible.

      Workaround

      Patch the module class or patch the ModuleMap2BeanTransformer in webapp. For the later, the map moduleClassToModuleName created in the constructor should take the componenproviders type mapping into account when setting up the entries.

        Acceptance criteria

              Unassigned Unassigned
              pguettler Philipp Guettler
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:

                  Bug DoR
                  Task DoD