Program: 15981
Project: 15981
Buggy source:
public void setShadowHost(Component host,Component insertBefore){
  if (getParent() != null) {
    throw new UiException("String_Node_Str" + this + "String_Node_Str");
  }
  if (host == null) {
    throw new UiException("String_Node_Str" + this + "String_Node_Str");
  }
  if (_host != null) {
    throw new UiException("String_Node_Str" + this + "String_Node_Str");
  }
  _host=host;
  onHostAttached(host);
  _nextInsertion=insertBefore;
  if (insertBefore != null) {
    _previousInsertion=insertBefore.getPreviousSibling();
  }
 else {
    List<ShadowElement> shadowRoots=((ComponentCtrl)host).getShadowRoots();
    ShadowElement lastShadowElement=shadowRoots.isEmpty() ? null : shadowRoots.get(shadowRoots.size() - 1);
    Component prev=(Component)lastShadowElement;
    HtmlShadowElement prevOwner=asShadow(lastShadowElement);
    Component lastChild=host.getLastChild();
    if (prevOwner == null) {
      prev=lastChild;
    }
 else {
switch (HtmlShadowElement.inRange(prevOwner,lastChild)) {
case NEXT:
case AFTER_NEXT:
        prev=lastChild;
      break;
case UNKNOWN:
    boolean skip=false;
  for (  ShadowElement se : shadowRoots) {
    if (asShadow(se)._previousInsertion == lastChild) {
      skip=true;
      break;
    }
  }
if (!skip) prev=lastChild;
break;
default :
}
}
_previousInsertion=prev;
if (prev == lastShadowElement && prev != null) {
prevOwner._nextInsertion=this;
}
}
((ComponentCtrl)host).addShadowRoot(this);
host.getDesktop().getWebApp().getConfiguration().afterShadowAttached(this,host);
}

Fixed version (ground truth):
public void setShadowHost(Component host,Component insertBefore){
  if (getParent() != null) {
    throw new UiException("String_Node_Str" + this + "String_Node_Str");
  }
  if (host == null) {
    throw new UiException("String_Node_Str" + this + "String_Node_Str");
  }
  if (_host != null) {
    throw new UiException("String_Node_Str" + this + "String_Node_Str");
  }
  _host=host;
  onHostAttached(host);
  _nextInsertion=insertBefore;
  if (insertBefore != null) {
    _previousInsertion=insertBefore.getPreviousSibling();
  }
 else {
    List<ShadowElement> shadowRoots=((ComponentCtrl)host).getShadowRoots();
    ShadowElement lastShadowElement=shadowRoots.isEmpty() ? null : shadowRoots.get(shadowRoots.size() - 1);
    Component prev=(Component)lastShadowElement;
    HtmlShadowElement prevOwner=asShadow(lastShadowElement);
    Component lastChild=host.getLastChild();
    if (prevOwner == null) {
      prev=lastChild;
    }
 else {
switch (HtmlShadowElement.inRange(prevOwner,lastChild)) {
case NEXT:
case AFTER_NEXT:
        prev=lastChild;
      break;
case UNKNOWN:
    boolean skip=false;
  for (  ShadowElement se : shadowRoots) {
    if (se == prevOwner)     break;
switch (HtmlShadowElement.inRange(asShadow(se),lastChild)) {
case UNKNOWN:
      break;
default :
    skip=true;
}
if (skip) break;
}
if (!skip) prev=lastChild;
break;
default :
}
}
_previousInsertion=prev;
if (prev == lastShadowElement && prev != null) {
prevOwner._nextInsertion=this;
}
}
((ComponentCtrl)host).addShadowRoot(this);
host.getDesktop().getWebApp().getConfiguration().afterShadowAttached(this,host);
}