Program: 16543
Project: 16543
Buggy source:
void setBeanAndRegisterBeanSameNodes(Component comp,Object val,Binding binding,String path,boolean autoConvert,Object rawval,List loadOnSaveInfos){
  Object orgVal=null;
  Object bean=null;
  BindingNode currentNode=_pathTree;
  boolean refChanged=false;
  String beanid=null;
  final List nodeids=parseExpression(path,"String_Node_Str");
  final List nodes=new ArrayList(nodeids.size());
  final Iterator it=nodeids.iterator();
  if (it != null && it.hasNext()) {
    beanid=(String)it.next();
    currentNode=(BindingNode)currentNode.getKidNode(beanid);
    if (currentNode == null) {
      throw new UiException("String_Node_Str" + path);
    }
    nodes.add(currentNode);
    bean=lookupBean(comp,beanid);
  }
 else {
    throw new UiException("String_Node_Str" + path);
  }
  if (!it.hasNext()) {
    orgVal=bean;
    if (Objects.equals(orgVal,val)) {
      return;
    }
    if (existsBean(beanid)) {
      setBean(beanid,val);
    }
 else     if (!setZScriptVariable(comp,beanid,val)) {
      comp.setAttribute(beanid,val,true);
    }
    refChanged=true;
  }
 else {
    if (bean == null) {
      return;
    }
    int sz=nodeids.size() - 2;
    for (; bean != null && it.hasNext() && sz > 0; --sz) {
      beanid=(String)it.next();
      currentNode=(BindingNode)currentNode.getKidNode(beanid);
      if (currentNode == null) {
        throw new UiException("String_Node_Str" + path);
      }
      nodes.add(currentNode);
      try {
        bean=Fields.get(bean,beanid);
      }
 catch (      NoSuchMethodException ex) {
        if (bean instanceof Map) {
          bean=((Map)bean).get(beanid);
        }
 else {
          throw UiException.Aide.wrap(ex);
        }
      }
    }
    if (bean == null) {
      return;
    }
    beanid=(String)it.next();
    try {
      orgVal=Fields.get(bean,beanid);
      if (Objects.equals(orgVal,val)) {
        return;
      }
      Fields.set(bean,beanid,val,autoConvert);
    }
 catch (    NoSuchMethodException ex) {
      if (bean instanceof Map) {
        ((Map)bean).put(beanid,val);
      }
 else {
        throw UiException.Aide.wrap(ex);
      }
    }
catch (    ModificationException ex) {
      throw UiException.Aide.wrap(ex);
    }
    if (!isPrimitive(val) && !isPrimitive(orgVal)) {
      currentNode=(BindingNode)currentNode.getKidNode(beanid);
      if (currentNode == null) {
        throw new UiException("String_Node_Str" + path);
      }
      nodes.add(currentNode);
      bean=orgVal;
      refChanged=true;
    }
  }
  if (val != null) {
    if (refChanged && !binding.isLoadable() && binding.isSavable()) {
      registerBeanNode(val,currentNode);
    }
    if (rawval instanceof Component) {
      Binding varbinding=getBinding((Component)rawval,"String_Node_Str");
      if (varbinding != null) {
        registerBeanNode(val,currentNode);
        getBeanAndRegisterBeanSameNodes((Component)rawval,varbinding.getExpression());
      }
    }
  }
  if (!comp.isListenerAvailable("String_Node_Str",true)) {
    comp.addEventListener("String_Node_Str",_listener);
  }
  Object[] loadOnSaveInfo=new Object[]{this,currentNode,binding,(refChanged ? val : bean),Boolean.valueOf(refChanged),nodes,comp};
  if (loadOnSaveInfos != null) {
    loadOnSaveInfos.add(loadOnSaveInfo);
  }
 else {
    Events.postEvent(new Event("String_Node_Str",comp,loadOnSaveInfo));
  }
}

Fixed version (ground truth):
void setBeanAndRegisterBeanSameNodes(Component comp,Object val,Binding binding,String path,boolean autoConvert,Object rawval,List loadOnSaveInfos){
  Object orgVal=null;
  Object bean=null;
  BindingNode currentNode=_pathTree;
  boolean refChanged=false;
  String beanid=null;
  final List nodeids=parseExpression(path,"String_Node_Str");
  final List nodes=new ArrayList(nodeids.size());
  final Iterator it=nodeids.iterator();
  if (it != null && it.hasNext()) {
    beanid=(String)it.next();
    currentNode=(BindingNode)currentNode.getKidNode(beanid);
    if (currentNode == null) {
      throw new UiException("String_Node_Str" + path);
    }
    nodes.add(currentNode);
    bean=lookupBean(comp,beanid);
  }
 else {
    throw new UiException("String_Node_Str" + path);
  }
  if (!it.hasNext()) {
    orgVal=bean;
    if (Objects.equals(orgVal,val)) {
      return;
    }
    if (existsBean(beanid)) {
      setBean(beanid,val);
    }
 else     if (!setZScriptVariable(comp,beanid,val)) {
      final Object owner=comp.getSpaceOwner();
      if (owner instanceof Page) {
        ((Page)owner).setAttribute(beanid,val);
      }
 else {
        ((Component)owner).setAttribute(beanid,val,true);
      }
    }
    refChanged=true;
  }
 else {
    if (bean == null) {
      return;
    }
    int sz=nodeids.size() - 2;
    for (; bean != null && it.hasNext() && sz > 0; --sz) {
      beanid=(String)it.next();
      currentNode=(BindingNode)currentNode.getKidNode(beanid);
      if (currentNode == null) {
        throw new UiException("String_Node_Str" + path);
      }
      nodes.add(currentNode);
      try {
        bean=Fields.get(bean,beanid);
      }
 catch (      NoSuchMethodException ex) {
        if (bean instanceof Map) {
          bean=((Map)bean).get(beanid);
        }
 else {
          throw UiException.Aide.wrap(ex);
        }
      }
    }
    if (bean == null) {
      return;
    }
    beanid=(String)it.next();
    try {
      orgVal=Fields.get(bean,beanid);
      if (Objects.equals(orgVal,val)) {
        return;
      }
      Fields.set(bean,beanid,val,autoConvert);
    }
 catch (    NoSuchMethodException ex) {
      if (bean instanceof Map) {
        ((Map)bean).put(beanid,val);
      }
 else {
        throw UiException.Aide.wrap(ex);
      }
    }
catch (    ModificationException ex) {
      throw UiException.Aide.wrap(ex);
    }
    if (!isPrimitive(val) && !isPrimitive(orgVal)) {
      currentNode=(BindingNode)currentNode.getKidNode(beanid);
      if (currentNode == null) {
        throw new UiException("String_Node_Str" + path);
      }
      nodes.add(currentNode);
      bean=orgVal;
      refChanged=true;
    }
  }
  if (val != null) {
    if (refChanged && !binding.isLoadable() && binding.isSavable()) {
      registerBeanNode(val,currentNode);
    }
    if (rawval instanceof Component) {
      Binding varbinding=getBinding((Component)rawval,"String_Node_Str");
      if (varbinding != null) {
        registerBeanNode(val,currentNode);
        getBeanAndRegisterBeanSameNodes((Component)rawval,varbinding.getExpression());
      }
    }
  }
  if (!comp.isListenerAvailable("String_Node_Str",true)) {
    comp.addEventListener("String_Node_Str",_listener);
  }
  Object[] loadOnSaveInfo=new Object[]{this,currentNode,binding,(refChanged ? val : bean),Boolean.valueOf(refChanged),nodes,comp};
  if (loadOnSaveInfos != null) {
    loadOnSaveInfos.add(loadOnSaveInfo);
  }
 else {
    Events.postEvent(new Event("String_Node_Str",comp,loadOnSaveInfo));
  }
}