Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-3729

getDesktop() sometimes returns NULL causing NPE

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 10.1.0
    • 8.0.3, 10.0.0
    • None
    • apache-tomcat-8.0.24

      Steps to reproduce

      1. zk-3729.zul
      2. open 2 browser tabs
      3. in the 1st tab, click "long op" button
      4. immediately switch to the 2nd tab, click "logout" button
      5. check server console log

      Current Result

      end users see an error dialog.

      Errors in a server console:

      java.lang.NullPointerException
      at org.zkoss.zk.ui.AbstractComponent.getAttachedUiEngine(AbstractComponent.java:379)
      at org.zkoss.zk.ui.AbstractComponent.invalidate(AbstractComponent.java:1673)
      at org.zkoss.zul.impl.GridDataLoader.doListDataChange(GridDataLoader.java:113)
      at org.zkoss.zkmax.zul.impl.LiveGridDataLoader.doListDataChange(LiveGridDataLoader.java:95)
      at org.zkoss.zul.Grid.onListDataChange(Grid.java:1128)
      at org.zkoss.zul.Grid$2.onChange(Grid.java:895)
      at org.zkoss.zul.AbstractListModel.fireEvent(AbstractListModel.java:77)
      at org.zkoss.zul.ListModelList.add(ListModelList.java:170)
      at bug.ZK3729Composer.longOp(ZK3729Composer.java:33)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      at org.zkoss.zk.ui.select.Selectors$ComposerEventListener.onEvent(Selectors.java:673)
      at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:3170)
      at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:3140)
      at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:3082)
      at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138)
      at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1888)
      at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1660)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1323)
      at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:528)
      at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:404)
      at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:412)
      ...
      2024-06-06 14:49:12 [ERROR] UiEngineImpl:1633 - Unable to generate custom error page, /WEB-INF/sys/error.zul
      java.lang.NullPointerException
      at org.zkoss.zk.ui.impl.Utils.newComposer(Utils.java:91)
      at org.zkoss.zk.ui.metainfo.ComponentInfo.toComposer(ComponentInfo.java:361)
      at org.zkoss.zk.ui.metainfo.ComponentInfo.toComposers(ComponentInfo.java:331)
      at org.zkoss.zk.ui.metainfo.ComponentInfo.resolveComposer(ComponentInfo.java:319)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:898)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:891)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:778)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:742)
      at org.zkoss.zk.ui.impl.UiEngineImpl.createComponents(UiEngineImpl.java:1145)
      at org.zkoss.zk.ui.impl.AbstractExecution.createComponents0(AbstractExecution.java:342)
      at org.zkoss.zk.ui.impl.AbstractExecution.createComponents(AbstractExecution.java:303)
      at org.zkoss.zk.ui.impl.UiEngineImpl.visualizeErrors(UiEngineImpl.java:1616)
      at org.zkoss.zk.ui.impl.UiEngineImpl.getResponses(UiEngineImpl.java:1570)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1339)
      at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:528)
      at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:404)
      at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:412)

      Expected result

      one log or show nothing (need a discussion)

      Debug Info

      Options for Handling such a NullPointerException:

      1. pring the Error Stack Trace (current): This approach directly shows the error stack trace in the logs, which helps developers understand what went wrong but can be overwhelming for end-users and clutter the logs.
      2. print a Warning/Debug Log: Log a warning message indicating that the desktop is no longer available. This approach keeps the log cleaner and informs developers of the specific issue without overwhelming them with stack traces.
      3. print Nothing: Silently handle the absence of the desktop by not processing any actions. This approach ensures the user interface does not attempt to interact with a non-existent desktop, thus avoiding unnecessary errors.

      Suggested Approach:

      Option 2 (print a log) is generally the best practice because it informs developers about the issue without cluttering the logs with full stack traces. Additionally, it ensures that users are not presented with error messages that they cannot resolve.
      Option 3 is also fine. The potential worry is that end-users or app developers might not understand why nothing rendered because they don't find a desktop is destroyed.

      User real use case

      Almost every day we can find in our application log these examples of the same problem

      • IMHO it is problem with lost ZK desktop after session timeout, when client tries to do some action in browser
      • for example i have a testcase:
        • I have 2 browser tabs for the same application (different pages and desktops)
        • in first tab I use a long operation action
        • in second tab I use logout action
        • the NullPointerException is thrown for the first tab since desktop is NULL

      I am not able to find solution on the internet so I am asking here.

      Examples:

      2017-08-09T10:15:49,222 [/orionweb] [{user=mrz}] ERROR org.zkoss.zul.Grid-
      java.lang.NullPointerException
      	at org.zkoss.zk.ui.AbstractComponent.addMoved(AbstractComponent.java:483) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.AbstractComponent.setParent(AbstractComponent.java:1257) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zul.Grid$Renderer.render(Grid.java:1148) [zul-8.0.3.1.jar:?]
      	at org.zkoss.zul.Grid.doInitRenderer(Grid.java:1020) [zul-8.0.3.1.jar:?]
      	at org.zkoss.zul.Grid.onInitRender(Grid.java:977) [zul-8.0.3.1.jar:?]
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51]
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_51]
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_51]
      	at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_51]
      	at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:3144) [zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:3075) [zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138) [zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1853) [zk-8.0.3.1.jar:?]
      
      2017-08-09T10:15:50,213 [/orionweb] [{user=mrz}] ERROR org.zkoss.zk.ui.impl.UiEngineImpl-
      java.lang.NullPointerException
      	at org.zkoss.zk.ui.AbstractComponent.getAttachedUiEngine(AbstractComponent.java:376) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.AbstractComponent.smartUpdate(AbstractComponent.java:1844) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.AbstractComponent.smartUpdate(AbstractComponent.java:1818) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.AbstractComponent.smartUpdate(AbstractComponent.java:1884) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zul.Row.setLoaded(Row.java:181) ~[zul-8.0.3.1.jar:?]
      	at org.zkoss.zul.Grid$Renderer.render(Grid.java:1152) ~[zul-8.0.3.1.jar:?]
      	at org.zkoss.zul.Grid.doInitRenderer(Grid.java:1020) ~[zul-8.0.3.1.jar:?]
      	at org.zkoss.zul.Grid.onInitRender(Grid.java:977) ~[zul-8.0.3.1.jar:?]
      
      2016-11-01T10:02:11,294 [] [{}] [http-nio-8102-exec-41] ERROR Fatal- 
      java.lang.NullPointerException
      	at org.zkoss.zk.ui.AbstractComponent.addMoved(AbstractComponent.java:483) ~[zk-8.0.2.1.jar:?]
      	at org.zkoss.zk.ui.AbstractComponent.setParent(AbstractComponent.java:1257) ~[zk-8.0.2.1.jar:?]
      	at org.zkoss.zk.ui.AbstractComponent.insertBefore(AbstractComponent.java:1356) ~[zk-8.0.2.1.jar:?]
      	at org.zkoss.zk.ui.AbstractComponent.appendChild(AbstractComponent.java:1534) ~[zk-8.0.2.1.jar:?]
      	at cz.ccv.orionweb.composers.general.DashboardComposer.addDocumentButton(DashboardComposer.java:468) ~[DashboardComposer.class:?]
      	at cz.ccv.orionweb.composers.general.DashboardComposer.addDocumentButton(DashboardComposer.java:490) ~[DashboardComposer.class:?]
      	at cz.ccv.orionweb.composers.general.DashboardComposer.fillWaitingForResolved(DashboardComposer.java:221) ~[DashboardComposer.class:?]
      	at cz.ccv.orionweb.composers.general.DashboardComposer.doAfterCompose(DashboardComposer.java:105) ~[DashboardComposer.class:?]
      
      2016-11-01T10:02:11,327 [/orionweb] [{user=kraftcs}] [http-nio-8102-exec-41] ERROR org.zkoss.zk.ui.impl.UiEngineImpl- 
      java.lang.NullPointerException
      	at org.zkoss.zk.ui.AbstractComponent.redraw(AbstractComponent.java:2156) ~[zk-8.0.2.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiVisualizer.redraw(UiVisualizer.java:1003) ~[zk-8.0.2.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiVisualizer.getResponses(UiVisualizer.java:699) ~[zk-8.0.2.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.getResponses(UiEngineImpl.java:1538) [zk-8.0.2.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1344) [zk-8.0.2.1.jar:?]
      	at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:606) [zk-8.0.2.1.jar:8.0.2.1]
      	at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:482) [zk-8.0.2.1.jar:8.0.2.1]
      	at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:490) [zk-8.0.2.1.jar:8.0.2.1]
      
      2017-05-18T09:15:38,848 [/orionweb] [{user=gstobchod}] [http-nio-8102-exec-76] ERROR org.zkoss.zk.ui.impl.UiEngineImpl- 
      java.lang.NullPointerException
      	at org.zkoss.zk.ui.AbstractComponent.redraw(AbstractComponent.java:2156) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiVisualizer.redraw(UiVisualizer.java:1003) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiVisualizer.getResponses(UiVisualizer.java:699) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.getResponses(UiEngineImpl.java:1538) [zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1344) [zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:606) [zk-8.0.3.1.jar:8.0.3.1]
      	at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:482) [zk-8.0.3.1.jar:8.0.3.1]
      	at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:490) [zk-8.0.3.1.jar:8.0.3.1]
      
      2017-08-07T15:53:54,576 [/orionadmin] [{user=mrz}] ERROR org.zkoss.zk.ui.impl.UiEngineImpl- Unable to generate custom error page, /WEB-INF/zk/unsecure/exception/error.zul
      java.lang.NullPointerException
      	at org.zkoss.zk.ui.AbstractComponent.addMoved(AbstractComponent.java:483) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.AbstractComponent.setPageBefore(AbstractComponent.java:432) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.AbstractUiFactory.newComponent(AbstractUiFactory.java:142) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:925) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:895) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:777) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:841) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:797) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:740) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.createComponents(UiEngineImpl.java:1150) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.AbstractExecution.createComponents0(AbstractExecution.java:346) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.AbstractExecution.createComponents(AbstractExecution.java:307) ~[zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.visualizeErrors(UiEngineImpl.java:1581) [zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.getResponses(UiEngineImpl.java:1535) [zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1344) [zk-8.0.3.1.jar:?]
      	at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:606) [zk-8.0.3.1.jar:8.0.3.1]
      	at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:482) [zk-8.0.3.1.jar:8.0.3.1]
      	at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:490) [zk-8.0.3.1.jar:8.0.3.1]
      

        1. errorMsg.png
          errorMsg.png
          13 kB
        2. zk-3729.zul
          0.2 kB
        3. ZK3729Composer.java
          1 kB

            jumperchen jumperchen
            Worsik Worsik
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: