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

Loading a null variable in a load binding throws a NullPointerException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 8.0.1
    • 8.0.0
    • None
    • Security Level: Jimmy
    • None

      problem description

      The code below throws a NullPointerException because vm.userAccount is null.

      <tab label="test" visible="@load(vm.userAccount.groupFlag)" />
      

      Steps to reproduce

      1. run the code below: vm.visible is null
        	<div  viewModel="@id('vm')@init('support.issue.IssueVM')">
        			<label visible="@load(vm.visible)" value="text" />
        	</div>	
        
      public class IssueVM {
      	private Boolean visible = null;
      
      	public Boolean getVisible() {
      		return visible;
      	}
      }
      

      actual result

      java.lang.NullPointerException
      	at org.zkoss.zk.ui.AbstractComponent$4.setValue(AbstractComponent.java:2852)
      	at org.zkoss.zk.ui.AbstractComponent$4.setValue(AbstractComponent.java:2850)
      	at org.zkoss.bind.impl.PropertyExpression.setValue(PropertyExpression.java:69)
      	at org.zkoss.bind.impl.LoadPropertyBindingImpl.load(LoadPropertyBindingImpl.java:88)
      	at org.zkoss.bind.impl.PropertyBindingHandler.doLoadBinding(PropertyBindingHandler.java:133)
      	at org.zkoss.bind.impl.PropertyBindingHandler.doLoad(PropertyBindingHandler.java:334)
      	at org.zkoss.bind.impl.BinderImpl.loadComponentProperties0(BinderImpl.java:2307)
      	at org.zkoss.bind.impl.BinderImpl.loadComponent0(BinderImpl.java:2276)
      	at org.zkoss.bind.impl.BinderImpl.loadComponent0(BinderImpl.java:2281)
      	at org.zkoss.bind.impl.BinderImpl.loadComponent(BinderImpl.java:2215)
      	at org.zkoss.bind.BindComposer$BinderKeeper$Loader.load(BindComposer.java:575)
      	at org.zkoss.bind.BindComposer$BinderKeeper.loadComponentForAllBinders(BindComposer.java:551)
      	at org.zkoss.bind.BindComposer.doAfterCompose(BindComposer.java:190)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.doAfterCompose(UiEngineImpl.java:588)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:931)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:877)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:748)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:822)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:771)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:709)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:452)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:358)
      	at org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:217)
      

      debug info

      • this issue doesn't happen in ZK 7
      • 8.0.1.FL.20151015-Eval also has the issue.

      Workaround

      • use <if test="vm.mightBeNullVar"> instead
      • visible="@load(!empty vm.visible and vm.visible)"

            jumperchen jumperchen
            hawk hawk
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour
                1h