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

Websockets NPE during encodeURL

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: 9.5.1
    • Fix Version/s: 9.6.0
    • Component/s: ZK Update Engine
    • Security Level: Jimmy
    • Environment:

      Description

      Steps to Reproduce

      append a default <image> (with no URL) in an activated server push thread

      <zk>
          <zscript><![CDATA[
              desktop.enableServerPush(true);
          ]]></zscript>
          <div id="parent">
              <button label="create image">
                  <attribute name="onClick"><![CDATA[
                      Desktop dt = desktop;
                      new Thread() {
                          public void run() {
                              Thread.sleep(200);
                              Executions.activate(dt);
                              parent.appendChild(new Image());
                              //more isolated way to reproduce without <image>
                              //System.out.println(Executions.getCurrent().encodeURL("~./img/spacer.gif"));
                              Executions.deactivate(dt);
                          }
                      }.start();
                  ]]></attribute>
              </button>
          </div>
      </zk>
      

      click the button "create image"

      Current Result

      java.lang.NullPointerException: null
      	at org.zkoss.web.servlet.Servlets.getExtWebCtxs(Servlets.java:1330)
      	at org.zkoss.web.servlet.Servlets.getExtendletContext(Servlets.java:1322)
      	at org.zkoss.web.servlet.http.Encodes.encodeURL0(Encodes.java:453)
      	at org.zkoss.web.servlet.http.Encodes.access$000(Encodes.java:48)
      	at org.zkoss.web.servlet.http.Encodes$1.encodeURL(Encodes.java:426)
      	at org.zkoss.web.servlet.http.Encodes.encodeURL(Encodes.java:399)
      	at org.zkoss.zk.ui.http.ExecutionImpl.encodeURL(ExecutionImpl.java:321)
      	at org.zkoss.zul.Image.getEncodedURL(Image.java:246)
      	at org.zkoss.zul.Image.renderProperties(Image.java:332)
      

      Expected Result

      render empty image, no error

      Debug Information

      the ExecutionImpl is created with a null servlet context (first parameter) during server push activation:

      https://github.com/zkoss/zkcml/blob/v9.5.1/zkmax/src/org/zkoss/zkmax/au/websocket/WebSocketServerPush.java#L194

      problem happens with "~./" urls in general not just with image urls

      System.out.println(Executions.getCurrent().encodeURL("~./img/spacer.gif"));
      

      Workaround

      create an image with the full image url

      new Image("/zkau/web/img/spacer.gif")
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rudyhuang rudyhuang
              Reporter:
              cor3000 cor3000
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - 1 day
                  1d
                  Remaining:
                  Time Spent - 6 hours Remaining Estimate - 2 hours
                  2h
                  Logged:
                  Time Spent - 6 hours Remaining Estimate - 2 hours
                  6h