Program: 8816
Project: 8816
Buggy source:
/** 
 * Writes this node type as an   {@code nt:nodeType} child of the givenparent node. An exception is thrown if the child node already exists, unless the  {@code allowUpdate} flag is set, in which case the existingnode is overwritten.
 * @param parent parent node under which to write this node type
 * @param allowUpdate whether to overwrite an existing type
 * @return The node type tree.
 * @throws RepositoryException if this type could not be written
 */
Tree writeTo(Tree parent,boolean allowUpdate) throws RepositoryException {
  String oakName=getOakName();
  Tree type=parent.getChild(oakName);
  if (!type.exists()) {
    type=parent.addChild(oakName);
    type.setProperty(JCR_PRIMARYTYPE,NT_NODETYPE,Type.NAME);
  }
 else   if (!allowUpdate) {
    throw new NodeTypeExistsException("String_Node_Str" + getName() + "String_Node_Str");
  }
  type.setProperty(JCR_NODETYPENAME,oakName,Type.NAME);
  if (superTypeOakNames.length > 0) {
    type.setProperty(JCR_SUPERTYPES,Arrays.asList(superTypeOakNames),Type.NAMES);
  }
 else {
    type.removeProperty(JCR_SUPERTYPES);
  }
  type.setProperty(JCR_IS_ABSTRACT,isAbstract);
  type.setProperty(JCR_IS_QUERYABLE,queryable);
  type.setProperty(JCR_ISMIXIN,isMixin);
  type.setProperty(JCR_HASORDERABLECHILDNODES,isOrderable);
  if (primaryItemOakName != null) {
    type.setProperty(JCR_PRIMARYITEMNAME,primaryItemOakName,Type.NAME);
  }
 else {
    type.removeProperty(JCR_PRIMARYITEMNAME);
  }
  Tree tree;
  int pdn=1;
  if (propertyDefinitionTemplates != null) {
    for (    PropertyDefinitionTemplateImpl pdt : propertyDefinitionTemplates) {
      String name=JCR_PROPERTYDEFINITION + "String_Node_Str" + pdn+++ "String_Node_Str";
      tree=type.getChild(name);
      if (!tree.exists()) {
        tree=type.addChild(name);
        tree.setProperty(JCR_PRIMARYTYPE,NT_PROPERTYDEFINITION,NAME);
      }
      pdt.writeTo(tree);
    }
  }
  tree=type.getChild(JCR_PROPERTYDEFINITION + "String_Node_Str" + pdn+++ "String_Node_Str");
  while (tree.exists()) {
    tree.remove();
    tree=type.getChild(JCR_PROPERTYDEFINITION + "String_Node_Str" + pdn+++ "String_Node_Str");
  }
  int ndn=1;
  if (nodeDefinitionTemplates != null) {
    for (    NodeDefinitionTemplateImpl ndt : nodeDefinitionTemplates) {
      String name=JCR_CHILDNODEDEFINITION + "String_Node_Str" + ndn+++ "String_Node_Str";
      tree=type.getChild(name);
      if (!tree.exists()) {
        tree=type.addChild(name);
        tree.setProperty(JCR_PRIMARYTYPE,NT_CHILDNODEDEFINITION,NAME);
      }
      ndt.writeTo(tree);
    }
  }
  tree=type.getChild(JCR_CHILDNODEDEFINITION + "String_Node_Str" + ndn+++ "String_Node_Str");
  while (tree.exists()) {
    tree.remove();
    tree=type.getChild(JCR_CHILDNODEDEFINITION + "String_Node_Str" + ndn+++ "String_Node_Str");
  }
  return type;
}

Fixed version (ground truth):
/** 
 * Writes this node type as an   {@code nt:nodeType} child of the givenparent node. An exception is thrown if the child node already exists, unless the  {@code allowUpdate} flag is set, in which case the existingnode is overwritten.
 * @param parent parent node under which to write this node type
 * @param allowUpdate whether to overwrite an existing type
 * @return The node type tree.
 * @throws RepositoryException if this type could not be written
 */
Tree writeTo(@Nonnull Tree parent,boolean allowUpdate) throws RepositoryException {
  String oakName=getOakName();
  if (oakName == null) {
    throw new RepositoryException("String_Node_Str");
  }
  Tree type=parent.getChild(oakName);
  if (!type.exists()) {
    type=parent.addChild(oakName);
    type.setProperty(JCR_PRIMARYTYPE,NT_NODETYPE,Type.NAME);
  }
 else   if (!allowUpdate) {
    throw new NodeTypeExistsException("String_Node_Str" + getName() + "String_Node_Str");
  }
  type.setProperty(JCR_NODETYPENAME,oakName,Type.NAME);
  if (superTypeOakNames.length > 0) {
    type.setProperty(JCR_SUPERTYPES,Arrays.asList(superTypeOakNames),Type.NAMES);
  }
 else {
    type.removeProperty(JCR_SUPERTYPES);
  }
  type.setProperty(JCR_IS_ABSTRACT,isAbstract);
  type.setProperty(JCR_IS_QUERYABLE,queryable);
  type.setProperty(JCR_ISMIXIN,isMixin);
  type.setProperty(JCR_HASORDERABLECHILDNODES,isOrderable);
  if (primaryItemOakName != null) {
    type.setProperty(JCR_PRIMARYITEMNAME,primaryItemOakName,Type.NAME);
  }
 else {
    type.removeProperty(JCR_PRIMARYITEMNAME);
  }
  Tree tree;
  int pdn=1;
  if (propertyDefinitionTemplates != null) {
    for (    PropertyDefinitionTemplateImpl pdt : propertyDefinitionTemplates) {
      String name=JCR_PROPERTYDEFINITION + "String_Node_Str" + pdn+++ "String_Node_Str";
      tree=type.getChild(name);
      if (!tree.exists()) {
        tree=type.addChild(name);
        tree.setProperty(JCR_PRIMARYTYPE,NT_PROPERTYDEFINITION,NAME);
      }
      pdt.writeTo(tree);
    }
  }
  tree=type.getChild(JCR_PROPERTYDEFINITION + "String_Node_Str" + pdn+++ "String_Node_Str");
  while (tree.exists()) {
    tree.remove();
    tree=type.getChild(JCR_PROPERTYDEFINITION + "String_Node_Str" + pdn+++ "String_Node_Str");
  }
  int ndn=1;
  if (nodeDefinitionTemplates != null) {
    for (    NodeDefinitionTemplateImpl ndt : nodeDefinitionTemplates) {
      String name=JCR_CHILDNODEDEFINITION + "String_Node_Str" + ndn+++ "String_Node_Str";
      tree=type.getChild(name);
      if (!tree.exists()) {
        tree=type.addChild(name);
        tree.setProperty(JCR_PRIMARYTYPE,NT_CHILDNODEDEFINITION,NAME);
      }
      ndt.writeTo(tree);
    }
  }
  tree=type.getChild(JCR_CHILDNODEDEFINITION + "String_Node_Str" + ndn+++ "String_Node_Str");
  while (tree.exists()) {
    tree.remove();
    tree=type.getChild(JCR_CHILDNODEDEFINITION + "String_Node_Str" + ndn+++ "String_Node_Str");
  }
  return type;
}