aem-core-wcm-components: [Form Container] Proxy extension model class of Form Container results in infinite loop

Bug Report

Current Behavior Extending the Container interface and implementing a new model class that proxies the WCM Core ContainerImpl results in an infinite loop on sling model instantiation for a Form Container added to a page. The issue is coming from the @PostConstruct implementation of ContainerImpl, which is calling FormsHelper which eventually executes a sling dispatcher include that attempts to adapt to the sling model again, and thus the cycle starts.

Expected behavior/code Extension via the proxy method is expected to be supported, to allow functionality to be added/modified from provided defaults.

Attempted implementation

import aQute.bnd.annotation.ConsumerType;
import com.adobe.cq.wcm.core.components.models.form.Container;

@ConsumerType
public interface HS2Container extends Container {

}
import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.wcm.core.components.models.form.Container;
import com.hs2solutions.aem.base.core.models.form.HS2Container;
import java.util.Map;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Via;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.via.ForcedResourceType;

@Model(
        adaptables = {Resource.class, SlingHttpServletRequest.class},
        adapters = {Container.class, HS2Container.class},
        resourceType = "hs2/components/content/form/container"
)
public class HS2ContainerImpl implements HS2Container {
    @Self
    @Via(type = ForcedResourceType.class, value = "core/wcm/components/form/container/v2/container")
    private Container superTypeContainer;

    @Override
    public String getMethod() {
        return superTypeContainer.getMethod();
    }

    @Override
    public String getAction() {
        return superTypeContainer.getAction();
    }

    @Override
    public String getId() {
        return superTypeContainer.getId();
    }

    @Override
    public String getName() {
        return superTypeContainer.getName();
    }

    @Override
    public String getEnctype() {
        return superTypeContainer.getEnctype();
    }

    @Override
    public String getResourceTypeForDropArea() {
        return superTypeContainer.getResourceTypeForDropArea();
    }

    @Override
    public String getRedirect() {
        return superTypeContainer.getRedirect();
    }

    @Override
    public String[] getExportedItemsOrder() {
        return superTypeContainer.getExportedItemsOrder();
    }

    @Override
    public Map<String, ? extends ComponentExporter> getExportedItems() {
        return superTypeContainer.getExportedItems();
    }

    @Override
    public String getExportedType() {
        return superTypeContainer.getExportedType();
    }
}

Resulting stack trace loop

	at org.apache.sling.models.impl.ModelAdapterFactory.invokePostConstruct(ModelAdapterFactory.java:896)
	at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:703)
	at org.apache.sling.models.impl.ModelAdapterFactory.internalCreateModel(ModelAdapterFactory.java:394)
	at org.apache.sling.models.impl.ModelAdapterFactory.createModel(ModelAdapterFactory.java:261)
	at org.apache.sling.scripting.sightly.models.impl.SlingModelsUseProvider.provide(SlingModelsUseProvider.java:126)
	at org.apache.sling.scripting.sightly.impl.engine.extension.use.UseRuntimeExtension.call(UseRuntimeExtension.java:73)
	at org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl.call(RenderContextImpl.java:69)
	at org.apache.sling.scripting.sightly.apps.core.wcm.components.form.container.v2.container.container_html.render(container_html.java:47)
	at org.apache.sling.scripting.sightly.java.compiler.RenderUnit.render(RenderUnit.java:48)
	at org.apache.sling.scripting.sightly.impl.engine.SightlyCompiledScript.eval(SightlyCompiledScript.java:61)
	at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:386)
	at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:184)
	at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:491)
	at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:552)
	at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:44)
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:77)
	at com.day.cq.wcm.core.impl.WCMDeveloperModeFilter.doFilterWithErrorHandling(WCMDeveloperModeFilter.java:164)
	at com.day.cq.wcm.core.impl.WCMDeveloperModeFilter.doFilter(WCMDeveloperModeFilter.java:135)
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)
	at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:138)
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)
	at com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:165)
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)
	at com.day.cq.wcm.core.impl.PageLockFilter.doFilter(PageLockFilter.java:91)
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)
	at com.day.cq.personalization.impl.TargetComponentFilter.doFilter(TargetComponentFilter.java:96)
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)
	at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:282)
	at org.apache.sling.engine.impl.SlingRequestProcessorImpl.dispatchRequest(SlingRequestProcessorImpl.java:322)
	at org.apache.sling.engine.impl.request.SlingRequestDispatcher.dispatch(SlingRequestDispatcher.java:211)
	at org.apache.sling.engine.impl.request.SlingRequestDispatcher.include(SlingRequestDispatcher.java:104)
	at com.day.cq.wcm.core.impl.WCMComponentFilter$ForwardRequestDispatcher.include(WCMComponentFilter.java:516)
	at com.day.cq.wcm.foundation.forms.FormsHelper.includeResource(FormsHelper.java:598)
	at com.day.cq.wcm.foundation.forms.FormsHelper.runAction(FormsHelper.java:267)
	at com.adobe.cq.wcm.core.components.internal.models.v1.form.ContainerImpl.runActionTypeInit(ContainerImpl.java:146)
	at com.adobe.cq.wcm.core.components.internal.models.v1.form.ContainerImpl.initModel(ContainerImpl.java:136)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.sling.models.impl.ModelAdapterFactory.invokePostConstruct(ModelAdapterFactory.java:896)
	at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:703)
	at org.apache.sling.models.impl.ModelAdapterFactory.internalCreateModel(ModelAdapterFactory.java:394)
	at org.apache.sling.models.impl.ModelAdapterFactory.createModel(ModelAdapterFactory.java:261)
	at org.apache.sling.scripting.sightly.models.impl.SlingModelsUseProvider.provide(SlingModelsUseProvider.java:126)
	at org.apache.sling.scripting.sightly.impl.engine.extension.use.UseRuntimeExtension.call(UseRuntimeExtension.java:73)
	at org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl.call(RenderContextImpl.java:69)
	at org.apache.sling.scripting.sightly.apps.core.wcm.components.form.container.v2.container.container_html.render(container_html.java:47)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 25 (10 by maintainers)

Commits related to this issue

Most upvoted comments

The code for this issue is merged to master and will be available in the upcoming 2.8.0 release.