Program: 15839
Project: 15839
Buggy source:
/** 
 * Returns the component array filter out shadows if any. (Most often used for the component developer to invoke  {@link Template#create(Component,Component,org.zkoss.xel.VariableResolver,org.zkoss.zk.ui.util.Composer)}by themselves and invoke this to filter out shadows.
 */
public static final Component[] filterOutShadows(Component[] shadows){
  if (shadows == null || shadows.length == 0)   return shadows;
  int length=shadows.length;
  if (length == 1) {
    if (shadows[0] instanceof ShadowElement) {
      ShadowElement se=((ShadowElement)shadows[0]);
      return se.getDistributedChildren().toArray(new Component[0]);
    }
  }
 else {
    Component parent=null;
    Component start=null;
    if (shadows[0] instanceof ShadowElementCtrl) {
      ShadowElementCtrl se=((ShadowElementCtrl)shadows[0]);
      start=se.getFirstInsertion();
    }
 else {
      start=shadows[0];
      parent=start.getParent();
    }
    if (parent instanceof ComponentCtrl) {
      ComponentCtrl pCtrl=(ComponentCtrl)parent;
      if (pCtrl.getShadowRoots().isEmpty())       return shadows;
    }
    Component end=null;
    if (shadows[0] instanceof ShadowElementCtrl) {
      ShadowElementCtrl se=((ShadowElementCtrl)shadows[length - 1]);
      start=se.getLastInsertion();
    }
 else {
      end=shadows[length - 1];
    }
    LinkedList<Component> list=new LinkedList<Component>();
    while (start != null) {
      list.add(start);
      if (start == end)       break;
      start=start.getNextSibling();
    }
    return list.toArray(new Component[0]);
  }
  return shadows;
}

Fixed version (ground truth):
/** 
 * Returns the component array filter out shadows if any. (Most often used for the component developer to invoke  {@link Template#create(Component,Component,org.zkoss.xel.VariableResolver,org.zkoss.zk.ui.util.Composer)}by themselves and invoke this to filter out shadows.
 */
public static final Component[] filterOutShadows(Component[] shadows){
  if (shadows == null || shadows.length == 0)   return shadows;
  int length=shadows.length;
  if (length == 1) {
    if (shadows[0] instanceof ShadowElement) {
      ShadowElement se=((ShadowElement)shadows[0]);
      if (se.getDistributedChildren().isEmpty()) {
        if (((ShadowElementCtrl)se).isDynamicValue()) {
          Events.sendEvent(new Event("String_Node_Str",(Component)se));
          Events.sendEvent(new Event("String_Node_Str",(Component)se));
        }
      }
      return se.getDistributedChildren().toArray(new Component[0]);
    }
  }
 else {
    Component parent=null;
    Component start=null;
    if (shadows[0] instanceof ShadowElementCtrl) {
      ShadowElementCtrl se=((ShadowElementCtrl)shadows[0]);
      start=se.getFirstInsertion();
    }
 else {
      start=shadows[0];
      parent=start.getParent();
    }
    if (parent instanceof ComponentCtrl) {
      ComponentCtrl pCtrl=(ComponentCtrl)parent;
      if (pCtrl.getShadowRoots().isEmpty())       return shadows;
    }
    Component end=null;
    if (shadows[0] instanceof ShadowElementCtrl) {
      ShadowElementCtrl se=((ShadowElementCtrl)shadows[length - 1]);
      start=se.getLastInsertion();
    }
 else {
      end=shadows[length - 1];
    }
    LinkedList<Component> list=new LinkedList<Component>();
    while (start != null) {
      list.add(start);
      if (start == end)       break;
      start=start.getNextSibling();
    }
    return list.toArray(new Component[0]);
  }
  return shadows;
}