tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tõnis Pool (JIRA) <j...@apache.org>
Subject [jira] [Updated] (TOMEE-1913) CDI.current().getBeanManager() returns BeanManager of another webapp
Date Wed, 24 Aug 2016 10:20:20 GMT

     [ https://issues.apache.org/jira/browse/TOMEE-1913?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Tõnis Pool updated TOMEE-1913:
------------------------------
    Description: 
Took some time to figure this one out, but the javax.enterprise.inject.spi.CDI integration
point will return a bean manager of another webapp, when the current webapp doesn't have CDI
enabled.

This in turn will mess with JSF as it uses that integration point to detect whether CDI is
enabled or not. The end result is that TomEE hasn't started CDI for the webapp, but JSF thinks
it's available.

To reproduce:
1) Download apps.zip from [here|https://drive.google.com/file/d/0B6RrEwQ40kwddk84R2NINGw3alE/view?usp=sharing],
it contains 2 webapps as maven projects
2) Package and deploy the "deploy-first" webapp to TomEE 7.0.1
3) Package and deploy the "BeanManager_bug" webapp to TomEE 7.0.1
4) Access $SERVER_URL/BeanManager_bug/, notice the {{NullPointerException}}
5) Access $SERVER_URL/BeanManager_bug/test, notice the "helloworld" bean among the CDI beans,
it's from the "deploy-first" webapp.

I believe the problem is that MyFaces {{AbstractFacesInitializer#initCDIIntegration}} calls
the mentioned CDI.current().getBeanManager(), which should fail, but actually will return
"deploy-first" bean manager because of the fallback algorithm in {{ThreadSingletonServiceImpl#get(final
ClassLoader cl)}}, which returns the WebBeansContext with the most beans in it.

So for the "BeanManager_bug" webapp JSF thinks it has CDI, but actually doesn't, which means
it will use the CDIManagedBeanHandlerImpl instead of the DefaultViewScopeHandler, causing
the NPE as a symptom.

Just for reference, here's the NPE from accessing $SERVER_URL/BeanManager_bug/:
{noformat}
java.lang.NullPointerException
	org.apache.webbeans.web.context.WebContextsService.lazyStartSessionContext(WebContextsService.java:815)
	org.apache.webbeans.web.context.WebContextsService.getSessionContext(WebContextsService.java:739)
	org.apache.webbeans.web.context.WebContextsService.getCurrentContext(WebContextsService.java:277)
	org.apache.webbeans.container.BeanManagerImpl.getContext(BeanManagerImpl.java:287)
	org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:88)
	org.apache.webbeans.intercept.SessionScopedBeanInterceptorHandler.getContextualInstance(SessionScopedBeanInterceptorHandler.java:76)
	org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.get(NormalScopedBeanInterceptorHandler.java:70)
	org.apache.myfaces.cdi.view.ViewScopeBeanHolder$$OwbNormalScopeProxy0.generateUniqueViewScopeId(org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java)
	org.apache.myfaces.cdi.impl.CDIManagedBeanHandlerImpl.generateViewScopeId(CDIManagedBeanHandlerImpl.java:92)
	org.apache.myfaces.view.ViewScopeProxyMap.getWrapped(ViewScopeProxyMap.java:79)
	org.apache.myfaces.view.ViewScopeProxyMap.get(ViewScopeProxyMap.java:119)
	org.apache.myfaces.config.ManagedBeanBuilder.getScope(ManagedBeanBuilder.java:564)
	org.apache.myfaces.config.ManagedBeanBuilder.getNarrowestScope(ManagedBeanBuilder.java:464)
	org.apache.myfaces.config.ManagedBeanBuilder.isInValidScope(ManagedBeanBuilder.java:435)
	org.apache.myfaces.config.ManagedBeanBuilder.initializeProperties(ManagedBeanBuilder.java:319)
	org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:163)
	org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:333)
	org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:296)
	javax.el.CompositeELResolver.getValue(CompositeELResolver.java:63)
	org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:179)
	org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:94)
	org.apache.el.parser.AstValue.getValue(AstValue.java:137)
	org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
	org.apache.webbeans.el22.WrappedValueExpression.getValue(WrappedValueExpression.java:70)
	org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:96)
	javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:360)
	javax.faces.component.UIOutput.getValue(UIOutput.java:67)
	org.apache.myfaces.shared.renderkit.RendererUtils.getValue(RendererUtils.java:486)
	org.apache.myfaces.shared.renderkit.RendererUtils.getStringValue(RendererUtils.java:329)
	org.apache.myfaces.shared.renderkit.html.HtmlTextRendererBase.renderOutput(HtmlTextRendererBase.java:86)
	org.apache.myfaces.shared.renderkit.html.HtmlTextRendererBase.encodeEnd(HtmlTextRendererBase.java:73)
	javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:674)
	javax.faces.component.UIComponentBase.encodeAll(UIComponentBase.java:554)
	javax.faces.component.UIComponentBase.encodeAll(UIComponentBase.java:550)
	org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1891)
	org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:313)
	javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:58)
	org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:116)
	org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:267)
	javax.faces.webapp.FacesServlet.service(FacesServlet.java:200)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
{noformat}

  was:
Took some time to figure this one out, but the javax.enterprise.inject.spi.CDI integration
point will return a bean manager of another webapp, when the current webapp doesn't have CDI
enabled.

This in turn will mess with JSF as it uses that integration point to detect whether CDI is
enabled or not. The end result is that TomEE hasn't started CDI for the webapp, but JSF thinks
it's available.

To reproduce:
1) Download apps.zip from [here|https://drive.google.com/file/d/0B6RrEwQ40kwddk84R2NINGw3alE/view?usp=sharing],
it contains 2 webapps as maven projects
2) Package and deploy the "deploy-first" webapp to TomEE 7.0.1
3) Package and deploy the "BeanManager_bug" webapp to TomEE 7.0.1
4) Access $SERVER_URL/BeanManager_bug/, notice the {{NullPointerException}}
5) Access $SERVER_URL/BeanManager_bug/test, notice the "helloworld" bean among the CDI beans,
it's from the "deploy-first" webapp.

I believe the problem is that MyFaces {{AbstractFacesInitializer#initCDIIntegration}} calls
the mentioned CDI.current().getBeanManager(), which should fail, but actually will return
"deploy-first" bean manager because of the fallback algorithm in {{ThreadSingletonServiceImpl#get(final
ClassLoader cl)}}, which returns the WebBeansContext with the most beans in it.

So for the "BeanManager_bug" webapp JSF thinks it has CDI, but actually doesn't, which means
it will use the CDIManagedBeanHandlerImpl instead of the DefaultViewScopeHandler.

Just for reference, here's the NPE from accessing $SERVER_URL/BeanManager_bug/:
{noformat}
java.lang.NullPointerException
	org.apache.webbeans.web.context.WebContextsService.lazyStartSessionContext(WebContextsService.java:815)
	org.apache.webbeans.web.context.WebContextsService.getSessionContext(WebContextsService.java:739)
	org.apache.webbeans.web.context.WebContextsService.getCurrentContext(WebContextsService.java:277)
	org.apache.webbeans.container.BeanManagerImpl.getContext(BeanManagerImpl.java:287)
	org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:88)
	org.apache.webbeans.intercept.SessionScopedBeanInterceptorHandler.getContextualInstance(SessionScopedBeanInterceptorHandler.java:76)
	org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.get(NormalScopedBeanInterceptorHandler.java:70)
	org.apache.myfaces.cdi.view.ViewScopeBeanHolder$$OwbNormalScopeProxy0.generateUniqueViewScopeId(org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java)
	org.apache.myfaces.cdi.impl.CDIManagedBeanHandlerImpl.generateViewScopeId(CDIManagedBeanHandlerImpl.java:92)
	org.apache.myfaces.view.ViewScopeProxyMap.getWrapped(ViewScopeProxyMap.java:79)
	org.apache.myfaces.view.ViewScopeProxyMap.get(ViewScopeProxyMap.java:119)
	org.apache.myfaces.config.ManagedBeanBuilder.getScope(ManagedBeanBuilder.java:564)
	org.apache.myfaces.config.ManagedBeanBuilder.getNarrowestScope(ManagedBeanBuilder.java:464)
	org.apache.myfaces.config.ManagedBeanBuilder.isInValidScope(ManagedBeanBuilder.java:435)
	org.apache.myfaces.config.ManagedBeanBuilder.initializeProperties(ManagedBeanBuilder.java:319)
	org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:163)
	org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:333)
	org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:296)
	javax.el.CompositeELResolver.getValue(CompositeELResolver.java:63)
	org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:179)
	org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:94)
	org.apache.el.parser.AstValue.getValue(AstValue.java:137)
	org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
	org.apache.webbeans.el22.WrappedValueExpression.getValue(WrappedValueExpression.java:70)
	org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:96)
	javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:360)
	javax.faces.component.UIOutput.getValue(UIOutput.java:67)
	org.apache.myfaces.shared.renderkit.RendererUtils.getValue(RendererUtils.java:486)
	org.apache.myfaces.shared.renderkit.RendererUtils.getStringValue(RendererUtils.java:329)
	org.apache.myfaces.shared.renderkit.html.HtmlTextRendererBase.renderOutput(HtmlTextRendererBase.java:86)
	org.apache.myfaces.shared.renderkit.html.HtmlTextRendererBase.encodeEnd(HtmlTextRendererBase.java:73)
	javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:674)
	javax.faces.component.UIComponentBase.encodeAll(UIComponentBase.java:554)
	javax.faces.component.UIComponentBase.encodeAll(UIComponentBase.java:550)
	org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1891)
	org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:313)
	javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:58)
	org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:116)
	org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:267)
	javax.faces.webapp.FacesServlet.service(FacesServlet.java:200)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
{noformat}


> CDI.current().getBeanManager() returns BeanManager of another webapp
> --------------------------------------------------------------------
>
>                 Key: TOMEE-1913
>                 URL: https://issues.apache.org/jira/browse/TOMEE-1913
>             Project: TomEE
>          Issue Type: Bug
>          Components: TomEE Core Server
>            Reporter: Tõnis Pool
>
> Took some time to figure this one out, but the javax.enterprise.inject.spi.CDI integration
point will return a bean manager of another webapp, when the current webapp doesn't have CDI
enabled.
> This in turn will mess with JSF as it uses that integration point to detect whether CDI
is enabled or not. The end result is that TomEE hasn't started CDI for the webapp, but JSF
thinks it's available.
> To reproduce:
> 1) Download apps.zip from [here|https://drive.google.com/file/d/0B6RrEwQ40kwddk84R2NINGw3alE/view?usp=sharing],
it contains 2 webapps as maven projects
> 2) Package and deploy the "deploy-first" webapp to TomEE 7.0.1
> 3) Package and deploy the "BeanManager_bug" webapp to TomEE 7.0.1
> 4) Access $SERVER_URL/BeanManager_bug/, notice the {{NullPointerException}}
> 5) Access $SERVER_URL/BeanManager_bug/test, notice the "helloworld" bean among the CDI
beans, it's from the "deploy-first" webapp.
> I believe the problem is that MyFaces {{AbstractFacesInitializer#initCDIIntegration}}
calls the mentioned CDI.current().getBeanManager(), which should fail, but actually will return
"deploy-first" bean manager because of the fallback algorithm in {{ThreadSingletonServiceImpl#get(final
ClassLoader cl)}}, which returns the WebBeansContext with the most beans in it.
> So for the "BeanManager_bug" webapp JSF thinks it has CDI, but actually doesn't, which
means it will use the CDIManagedBeanHandlerImpl instead of the DefaultViewScopeHandler, causing
the NPE as a symptom.
> Just for reference, here's the NPE from accessing $SERVER_URL/BeanManager_bug/:
> {noformat}
> java.lang.NullPointerException
> 	org.apache.webbeans.web.context.WebContextsService.lazyStartSessionContext(WebContextsService.java:815)
> 	org.apache.webbeans.web.context.WebContextsService.getSessionContext(WebContextsService.java:739)
> 	org.apache.webbeans.web.context.WebContextsService.getCurrentContext(WebContextsService.java:277)
> 	org.apache.webbeans.container.BeanManagerImpl.getContext(BeanManagerImpl.java:287)
> 	org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:88)
> 	org.apache.webbeans.intercept.SessionScopedBeanInterceptorHandler.getContextualInstance(SessionScopedBeanInterceptorHandler.java:76)
> 	org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.get(NormalScopedBeanInterceptorHandler.java:70)
> 	org.apache.myfaces.cdi.view.ViewScopeBeanHolder$$OwbNormalScopeProxy0.generateUniqueViewScopeId(org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java)
> 	org.apache.myfaces.cdi.impl.CDIManagedBeanHandlerImpl.generateViewScopeId(CDIManagedBeanHandlerImpl.java:92)
> 	org.apache.myfaces.view.ViewScopeProxyMap.getWrapped(ViewScopeProxyMap.java:79)
> 	org.apache.myfaces.view.ViewScopeProxyMap.get(ViewScopeProxyMap.java:119)
> 	org.apache.myfaces.config.ManagedBeanBuilder.getScope(ManagedBeanBuilder.java:564)
> 	org.apache.myfaces.config.ManagedBeanBuilder.getNarrowestScope(ManagedBeanBuilder.java:464)
> 	org.apache.myfaces.config.ManagedBeanBuilder.isInValidScope(ManagedBeanBuilder.java:435)
> 	org.apache.myfaces.config.ManagedBeanBuilder.initializeProperties(ManagedBeanBuilder.java:319)
> 	org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:163)
> 	org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:333)
> 	org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:296)
> 	javax.el.CompositeELResolver.getValue(CompositeELResolver.java:63)
> 	org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:179)
> 	org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:94)
> 	org.apache.el.parser.AstValue.getValue(AstValue.java:137)
> 	org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
> 	org.apache.webbeans.el22.WrappedValueExpression.getValue(WrappedValueExpression.java:70)
> 	org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:96)
> 	javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:360)
> 	javax.faces.component.UIOutput.getValue(UIOutput.java:67)
> 	org.apache.myfaces.shared.renderkit.RendererUtils.getValue(RendererUtils.java:486)
> 	org.apache.myfaces.shared.renderkit.RendererUtils.getStringValue(RendererUtils.java:329)
> 	org.apache.myfaces.shared.renderkit.html.HtmlTextRendererBase.renderOutput(HtmlTextRendererBase.java:86)
> 	org.apache.myfaces.shared.renderkit.html.HtmlTextRendererBase.encodeEnd(HtmlTextRendererBase.java:73)
> 	javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:674)
> 	javax.faces.component.UIComponentBase.encodeAll(UIComponentBase.java:554)
> 	javax.faces.component.UIComponentBase.encodeAll(UIComponentBase.java:550)
> 	org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1891)
> 	org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:313)
> 	javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:58)
> 	org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:116)
> 	org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:267)
> 	javax.faces.webapp.FacesServlet.service(FacesServlet.java:200)
> 	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
> 	org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message