[MAGNOLIA-8498] ModuleMap2BeanTransformer does not respect type-mapping Created: 11/Jul/22  Updated: 11/Jul/22

Status: Open
Project: Magnolia
Component/s: modulemechanism
Affects Version/s: 6.2.21
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Philipp Guettler Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled

 Description   

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.


Generated at Mon Feb 12 04:33:15 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.