vaadin / portlet

Portlet support for Vaadin Flow
https://vaadin.com
Other
2 stars 3 forks source link

PortletViewContext is initialised with the incorrect PortletView instance #191

Closed mshabarov closed 2 years ago

mshabarov commented 3 years ago

public class EventSourceView extends Div implements PortletView { private PortletViewContext eventContext;

public EventSourceView() {
     // event sending logic
}

@Override
public void onPortletViewContextInit(PortletViewContext context) {
    this.eventContext = context;
}

}

public class EventTargetPortlet extends VaadinPortlet { }

public class EventTargetView extends Div implements EventHandler { private PortletViewContext context;

public EventTargetView() {
}

@Override
public void handleEvent(PortletEvent event) {
     // event handling logic
}

}


When initialised, the `EventSourcePortlet` instance obtains `EventTargetView` (instead of expected `EventSourceView`) instance as a parameter of `VaadinPortlet::initComponent`. Then a new `PortletViewContext` is constructed with `EventTargetView` and this context is not being sent anywhere.
The next call to `VaadinPortlet::initComponent` with a correct `EventTargetView` doesn't trigger a `PortletViewContext` instance to be sent to the view through `onPortletViewContextInit()`, because `needViewInit = false` and the logic thinks it's already sent.

This leads to `EventTargetView` has an empty (null) context and, thus, when the event is being sent, it fails with NPE, because event fire logic work using this context.

- Minimal reproducible example
  It can be reproduced in `merged-liferay` branch with any of the following IT tests in Pluto:

IPCEventIT.sendEventFromSourceToTarget
IPCEventIT.sendEventFromSourceToTarget_portletsOnDifferentTabsReceiveEventsIndependently
IPCNotVaadinEventIT.sendEventFromVaadinToNonVaadin
IPCNotVaadinEventIT.sendEventFromNonVaadinToVaadin

- Expected and actual behavior
  `VaadinPortlet` instances should obtain only the view objects they are supposed to work with (generic class).
- Server logs 

[http-nio-8080-exec-2] ERROR com.vaadin.flow.portal.DefaultPortletErrorHandler - java.lang.NullPointerException java.lang.NullPointerException at com.vaadin.flow.portal.events.EventSourceView.lambda$new$c2950344$1(EventSourceView.java:31) at com.vaadin.flow.component.ComponentEventBus.fireEventForListener(ComponentEventBus.java:205) at com.vaadin.flow.component.ComponentEventBus.handleDomEvent(ComponentEventBus.java:373) at com.vaadin.flow.component.ComponentEventBus.lambda$addDomTrigger$dd1b7957$1(ComponentEventBus.java:264) at com.vaadin.flow.internal.nodefeature.ElementListenerMap.lambda$fireEvent$2(ElementListenerMap.java:443) at java.util.ArrayList.forEach(ArrayList.java:1257) at com.vaadin.flow.internal.nodefeature.ElementListenerMap.fireEvent(ElementListenerMap.java:443) at com.vaadin.flow.server.communication.rpc.EventRpcHandler.handleNode(EventRpcHandler.java:62) at com.vaadin.flow.server.communication.rpc.AbstractRpcInvocationHandler.handle(AbstractRpcInvocationHandler.java:66) at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocationData(ServerRpcHandler.java:438) at com.vaadin.flow.server.communication.ServerRpcHandler.lambda$handleInvocations$1(ServerRpcHandler.java:419) at java.util.ArrayList.forEach(ArrayList.java:1257) at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:419) at com.vaadin.flow.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:320) at com.vaadin.flow.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:92) at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40) at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1578) at com.vaadin.flow.portal.VaadinPortlet.handleRequest(VaadinPortlet.java:394) at com.vaadin.flow.portal.VaadinPortlet.serveResource(VaadinPortlet.java:333) at sun.reflect.GeneratedMethodAccessor104.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.pluto.container.bean.processor.AnnotatedMethod.invoke(AnnotatedMethod.java:187) at org.apache.pluto.container.bean.processor.PortletInvoker.invokePortletMethod(PortletInvoker.java:148) at org.apache.pluto.container.bean.processor.PortletInvoker.serveResource(PortletInvoker.java:305) at org.apache.pluto.driver.services.container.FilterChainImpl.doFilter(FilterChainImpl.java:292) at org.apache.pluto.driver.services.container.FilterChainImpl.processFilter(FilterChainImpl.java:145) at org.apache.pluto.driver.services.container.FilterManagerImpl.processFilter(FilterManagerImpl.java:118) at org.apache.pluto.container.driver.PortletServlet3.dispatch(PortletServlet3.java:512) at org.apache.pluto.container.driver.PortletServlet3.doPost(PortletServlet3.java:340) at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) 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.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:470) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:395) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:316) at org.apache.pluto.driver.container.DefaultPortletInvokerService.invoke(DefaultPortletInvokerService.java:243) at org.apache.pluto.driver.container.DefaultPortletInvokerService.serveResource(DefaultPortletInvokerService.java:162) at org.apache.pluto.container.impl.PortletContainerImpl.doServeResource(PortletContainerImpl.java:275) at org.apache.pluto.driver.PortalDriverServlet.doGet(PortalDriverServlet.java:182) at org.apache.pluto.driver.PortalDriverServlet.doPost(PortalDriverServlet.java:254) at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) 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.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270) 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:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:610) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) [http-nio-8080-exec-7] ERROR com.vaadin.flow.portal.DefaultPortletErrorHandler - java.lang.NullPointerException java.lang.NullPointerException at com.vaadin.flow.portal.events.EventSourceView.lambda$new$c2950344$1(EventSourceView.java:31) at com.vaadin.flow.component.ComponentEventBus.fireEventForListener(ComponentEventBus.java:205) at com.vaadin.flow.component.ComponentEventBus.handleDomEvent(ComponentEventBus.java:373) at com.vaadin.flow.component.ComponentEventBus.lambda$addDomTrigger$dd1b7957$1(ComponentEventBus.java:264) at com.vaadin.flow.internal.nodefeature.ElementListenerMap.lambda$fireEvent$2(ElementListenerMap.java:443) at java.util.ArrayList.forEach(ArrayList.java:1257) at com.vaadin.flow.internal.nodefeature.ElementListenerMap.fireEvent(ElementListenerMap.java:443) at com.vaadin.flow.server.communication.rpc.EventRpcHandler.handleNode(EventRpcHandler.java:62) at com.vaadin.flow.server.communication.rpc.AbstractRpcInvocationHandler.handle(AbstractRpcInvocationHandler.java:66) at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocationData(ServerRpcHandler.java:438) at com.vaadin.flow.server.communication.ServerRpcHandler.lambda$handleInvocations$1(ServerRpcHandler.java:419) at java.util.ArrayList.forEach(ArrayList.java:1257) at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:419) at com.vaadin.flow.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:320) at com.vaadin.flow.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:92) at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40) at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1578) at com.vaadin.flow.portal.VaadinPortlet.handleRequest(VaadinPortlet.java:394) at com.vaadin.flow.portal.VaadinPortlet.serveResource(VaadinPortlet.java:333) at sun.reflect.GeneratedMethodAccessor104.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.pluto.container.bean.processor.AnnotatedMethod.invoke(AnnotatedMethod.java:187) at org.apache.pluto.container.bean.processor.PortletInvoker.invokePortletMethod(PortletInvoker.java:148) at org.apache.pluto.container.bean.processor.PortletInvoker.serveResource(PortletInvoker.java:305) at org.apache.pluto.driver.services.container.FilterChainImpl.doFilter(FilterChainImpl.java:292) at org.apache.pluto.driver.services.container.FilterChainImpl.processFilter(FilterChainImpl.java:145) at org.apache.pluto.driver.services.container.FilterManagerImpl.processFilter(FilterManagerImpl.java:118) at org.apache.pluto.container.driver.PortletServlet3.dispatch(PortletServlet3.java:512) at org.apache.pluto.container.driver.PortletServlet3.doPost(PortletServlet3.java:340) at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) 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.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:470) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:395) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:316) at org.apache.pluto.driver.container.DefaultPortletInvokerService.invoke(DefaultPortletInvokerService.java:243) at org.apache.pluto.driver.container.DefaultPortletInvokerService.serveResource(DefaultPortletInvokerService.java:162) at org.apache.pluto.container.impl.PortletContainerImpl.doServeResource(PortletContainerImpl.java:275) at org.apache.pluto.driver.PortalDriverServlet.doGet(PortalDriverServlet.java:182) at org.apache.pluto.driver.PortalDriverServlet.doPost(PortalDriverServlet.java:254) at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) 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.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270) 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:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:610) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)


![image](https://user-images.githubusercontent.com/61410877/144377370-adc3fec4-fd90-4d0b-a347-3cad580cc525.png)

- Versions:
    - Vaadin Portlet version 3.0.0
    - Flow version 2.7-SNAPSHOT / 2.7.5
    - Portal (Pluto) version 3.1.0
    - Java version 1.8
    - OS version Mac OS
    - Browser version (if applicable) Chrome 95
mshabarov commented 2 years ago

This change causes this bug https://github.com/vaadin/portlet/commit/7a8521c4cc1cfb022517d44b3838ee6e24258e03