Program: 16052
Project: 16052
Buggy source:
public void beforeHostChildAdded(Component child,Component insertBefore,int indexOfInsertBefore){
  if (log.isDebugEnabled()) {
    log.warn("String_Node_Str" + child + "String_Node_Str"+ insertBefore+ "String_Node_Str"+ ShadowElementsCtrl.getCurrentInfo());
  }
  Object currentInfo=ShadowElementsCtrl.getCurrentInfo();
  if (indexOfInsertBefore < 0) {
    if (currentInfo instanceof HtmlShadowElement) {
      HtmlShadowElement asShadow=asShadow(currentInfo);
      if (isAncestor(this,asShadow)) {
        Component lastChild=asShadow.getLastChild();
        if (lastChild != null)         asShadow(lastChild)._nextInsertion=child;
      }
 else       if (asShadow.getShadowHostIfAny() != getShadowHostIfAny()) {
        if (_nextInsertion == null)         _nextInsertion=child;
      }
    }
 else {
      if (_nextInsertion == null)       _nextInsertion=child;
    }
  }
 else {
    Map<Component,Integer> indexMap=fillUpIndexMap(_firstInsertion,_lastInsertion);
    HtmlShadowElement node=queryIntersectedShadowIfAny(indexOfInsertBefore,indexMap);
    if (currentInfo instanceof HtmlShadowElement) {
      if (isAncestor(asShadow(currentInfo),node)) {
        adjustInsertionForInsertBefore(node,child,insertBefore);
      }
 else       if (!((HtmlShadowElement)currentInfo).getChildren().isEmpty()) {
        HtmlShadowElement currentShadow=asShadow(currentInfo);
        asShadow(currentShadow.getFirstChild())._nextInsertion=child;
      }
    }
 else     if (node != null) {
      if (this.getParent() != null || insertBefore != _firstInsertion) {
        adjustInsertionForInsertBefore(node,child,insertBefore);
      }
 else {
        _previousInsertion=child;
      }
    }
  }
}

Fixed version (ground truth):
public void beforeHostChildAdded(Component child,Component insertBefore,int indexOfInsertBefore){
  if (log.isDebugEnabled()) {
    log.warn("String_Node_Str" + child + "String_Node_Str"+ insertBefore+ "String_Node_Str"+ ShadowElementsCtrl.getCurrentInfo());
  }
  Object currentInfo=ShadowElementsCtrl.getCurrentInfo();
  if (indexOfInsertBefore < 0) {
    if (currentInfo instanceof HtmlShadowElement) {
      HtmlShadowElement asShadow=asShadow(currentInfo);
      if (isAncestor(this,asShadow)) {
        Component lastChild=asShadow.getLastChild();
        if (lastChild != null)         asShadow(lastChild)._nextInsertion=child;
      }
 else       if (asShadow.getShadowHostIfAny() != getShadowHostIfAny()) {
        if (_nextInsertion == null)         _nextInsertion=child;
      }
    }
 else {
      if (_nextInsertion == null)       _nextInsertion=child;
    }
  }
 else {
    Map<Component,Integer> indexMap=fillUpIndexMap(_firstInsertion,_lastInsertion);
    HtmlShadowElement node=queryIntersectedShadowIfAny(indexOfInsertBefore,indexMap);
    if (currentInfo instanceof HtmlShadowElement) {
      if (isAncestor(asShadow(currentInfo),node)) {
        adjustInsertionForInsertBefore(node,child,insertBefore);
      }
 else       if (!((HtmlShadowElement)currentInfo).getChildren().isEmpty()) {
        HtmlShadowElement currentShadow=asShadow(currentInfo);
        asShadow(currentShadow.getLastChild())._nextInsertion=child;
      }
    }
 else     if (node != null) {
      if (this.getParent() != null || insertBefore != _firstInsertion) {
        adjustInsertionForInsertBefore(node,child,insertBefore);
      }
 else {
        _previousInsertion=child;
      }
    }
  }
}