Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in CDIViewProvider.getParameters #254

Open
lubomirmatus opened this issue Jul 18, 2018 · 5 comments
Open

NullPointerException in CDIViewProvider.getParameters #254

lubomirmatus opened this issue Jul 18, 2018 · 5 comments
Labels
v8 Issues or PRs for Vaadin 8 version of the add-on

Comments

@lubomirmatus
Copy link

lubomirmatus commented Jul 18, 2018

I'm trying to upgrade from vaadin-cdi 2.0.0 to vaadin-cdi 3. I'm using vaadin-cdi 3.0.1 (issue also in 3.0.0) and I'm running into NullPointerException in CDIViewProvider.getParameters method at line 237. The 'lastViewAndParameters' member is null so then 'lastViewAndParameters.startsWith(viewName)' is throwing the exception.

MyUI.init() {
...
MainView mainView = (MainView) viewProvider.getView(MainView.VIEWNAME); // <-- exception inside
setContent(mainView);
...
}

This has been working fine in vaadin-cdi 2.0.0.

Stack trace:
júl 18, 2018 12:56:39 PM com.vaadin.server.DefaultErrorHandler doDefault
SEVERE:
java.lang.NullPointerException
at com.vaadin.cdi.CDIViewProvider.getParameters(CDIViewProvider.java:237)
at com.vaadin.cdi.CDIViewProvider.getView(CDIViewProvider.java:225)
at com.my.myui.MyUI.init(MyUI.java:193)
at com.vaadin.ui.UI.doInit(UI.java:771)
at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:218)
at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:76)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1601)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:445)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
at org.apache.tomee.catalina.OpenEJBSecurityListener$RequestCapturer.invoke(OpenEJBSecurityListener.java:97)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1457)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

@pekam pekam added the v8 Issues or PRs for Vaadin 8 version of the add-on label Jul 23, 2018
@kumm
Copy link
Contributor

kumm commented Sep 23, 2018

You should not need a ViewProvider at all.
Just @Inject your MainView. ( And do not forget to migrate to CDINavigator )

@lubomirmatus
Copy link
Author

Injecting MainView into UI is failing with error:
javax.enterprise.context.ContextNotActiveException: WebBeans context with scope type annotation @ViewScoped does not exist within current thread

MyUI:

@CDIUI("")
@Push
public class MyUI extends UI implements ServletContextListener {
    @Inject
    private CDINavigator navigator;

    @Inject
    private MainView mainView;

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        // ...
        navigator.init(this, mainView.getContent());
        // ...
    }

    // ...
}

MainView:

@CDIView(value=MainView.VIEWNAME)
public class MainView extends HorizontalLayout implements View {
    public final static String VIEWNAME = "main";

    // ...
}

The code does not reach the MyUi.init() method.
Stack trace:

okt 03, 2018 4:20:36 PM com.vaadin.server.DefaultErrorHandler doDefault
SEVERE: 
javax.enterprise.context.ContextNotActiveException: WebBeans context with scope type annotation @ViewScoped does not exist within current thread
	at org.apache.webbeans.container.BeanManagerImpl.getContext(BeanManagerImpl.java:304)
	at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:788)
	at org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:673)
	at org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:103)
	at org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:65)
	at org.apache.webbeans.portable.InjectionTargetImpl.injectFields(InjectionTargetImpl.java:220)
	at org.apache.webbeans.portable.InjectionTargetImpl.inject(InjectionTargetImpl.java:206)
	at org.apache.webbeans.portable.InjectionTargetImpl.inject(InjectionTargetImpl.java:196)
	at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:126)
	at org.apache.webbeans.component.ManagedBean.create(ManagedBean.java:67)
	at org.apache.deltaspike.core.util.context.ContextualStorage.createContextualInstance(ContextualStorage.java:131)
	at org.apache.deltaspike.core.util.context.AbstractContext.get(AbstractContext.java:129)
	at com.vaadin.cdi.internal.ContextWrapper.get(ContextWrapper.java:51)
	at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:799)
	at org.apache.webbeans.container.InjectableBeanManager.getReference(InjectableBeanManager.java:165)
	at com.vaadin.cdi.CDIUIProvider.createInstance(CDIUIProvider.java:97)
	at com.vaadin.cdi.CDIUIProvider$$OwbNormalScopeProxy0.createInstance(com/vaadin/cdi/CDIUIProvider.java)
	at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:193)
	at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:76)
	at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
	at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1601)
	at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:445)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
	at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
	at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
	at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
	at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
	at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
	at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
	at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
	at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
	at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.tomee.catalina.OpenEJBSecurityListener$RequestCapturer.invoke(OpenEJBSecurityListener.java:97)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1457)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)

@kumm
Copy link
Contributor

kumm commented Oct 7, 2018

Sorry, I've missed we are in init.
During page load a view context is activated only after UI is navigated to the requested view. It is done by Vaadin framework after UI.init. So ContextNotActiveException exception is ok.

Your use case seems strange to me. Even if @Inject works ManView bean is destroyed on the first view navigation.

@lubomirmatus
Copy link
Author

The code crashes before entering MyUi.init() method, probably on injecting MainView into MyUI.
So ... how to make it work ?

@kumm
Copy link
Contributor

kumm commented Nov 8, 2018

Yes it crashes during instantiating the UI. CDI can't find any active view context while injecting your viewscoped bean. As you can read before, a View context is activated after the UI is navigated to the requested view - after UI is instantiated and UI.init is run -.

Even if you were use lazy instantiation by @Inject Instance<MainView> mainView; it would crash in init on mainView.get().
You can't use ViewScoped beans until the UI is navigated to any view.

We can't make to work this way, so I should understand what you are trying to do.

Currently I see you are asking navigator to render views into a component that is provided only if you are already on a view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 Issues or PRs for Vaadin 8 version of the add-on
Projects
None yet
Development

No branches or pull requests

3 participants