Program: 100815
Project: 100815
Buggy source:
@Override public void startElement(final String uri,final String localName,final String name,final Attributes atts) throws SAXException {
  currentElement=null;
  final String cls=atts.getValue(ATTRIBUTE_NAME_CLASS);
  for (  final KeyrefInfo k : keyrefInfos) {
    if (k.type.matches(cls)) {
      currentElement=k;
    }
  }
  final AttributesImpl resAtts=new AttributesImpl(atts);
  hasChecked=false;
  empty=true;
  boolean valid=false;
  if (atts.getIndex(ATTRIBUTE_NAME_KEYREF) == -1) {
    if (keyrefLeval != 0) {
      keyrefLeval++;
      hasSubElem.pop();
      hasSubElem.push(true);
    }
  }
 else {
    elemName.push(name);
    if (keyrefLeval != 0) {
      keyrefLevalStack.push(keyrefLeval);
      hasSubElem.pop();
      hasSubElem.push(true);
    }
    hasSubElem.push(false);
    keyrefLeval=0;
    keyrefLeval++;
    final String keyrefValue=atts.getValue(ATTRIBUTE_NAME_KEYREF);
    final int slashIndex=keyrefValue.indexOf(SLASH);
    String keyName=keyrefValue;
    String tail="String_Node_Str";
    if (slashIndex != -1) {
      keyName=keyrefValue.substring(0,slashIndex);
      tail=keyrefValue.substring(slashIndex);
    }
    final String definition=definitionMap.get(keyName);
    if (definition != null) {
      doc=keyDefToDoc(definition);
      final Element elem=doc.getDocumentElement();
      final NamedNodeMap namedNodeMap=elem.getAttributes();
      if (currentElement != null && currentElement.isRefType) {
        String target=keyMap.get(keyName);
        if (target != null && target.length() != 0) {
          String target_output=target;
          final String scopeValue=elem.getAttribute(ATTRIBUTE_NAME_SCOPE);
          if (TOPIC_IMAGE.matches(currentElement.type)) {
            valid=true;
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_SCOPE);
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_HREF);
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_TYPE);
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_FORMAT);
            target_output=FileUtils.getRelativePathFromMap(fileName,target_output);
            target_output=normalizeHrefValue(target_output,tail);
            XMLUtils.addOrSetAttribute(resAtts,currentElement.refAttr,target_output);
          }
 else           if ("String_Node_Str".equals(scopeValue) || ATTR_SCOPE_VALUE_LOCAL.equals(scopeValue)) {
            if (!(MAPGROUP_D_MAPREF.matches(cls) && FileUtils.isDITAMapFile(target.toLowerCase()))) {
              target=FileUtils.replaceExtName(target,extName);
            }
            final File topicFile=new File(FileUtils.resolveFile(tempDir,target));
            if (topicFile.exists()) {
              final String topicId=this.getFirstTopicId(topicFile);
              target_output=FileUtils.getRelativePathFromMap(filepath,new File(tempDir,target).getAbsolutePath());
              valid=true;
              XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_HREF);
              XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_SCOPE);
              XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_TYPE);
              XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_FORMAT);
              target_output=normalizeHrefValue(target_output,tail,topicId);
              XMLUtils.addOrSetAttribute(resAtts,currentElement.refAttr,target_output);
            }
 else {
            }
          }
 else {
            valid=true;
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_SCOPE);
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_HREF);
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_TYPE);
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_FORMAT);
            target_output=normalizeHrefValue(target_output,tail);
            XMLUtils.addOrSetAttribute(resAtts,ATTRIBUTE_NAME_HREF,target_output);
          }
        }
 else         if (target == null || target.length() == 0) {
          valid=true;
          XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_SCOPE);
          XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_HREF);
          XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_TYPE);
          XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_FORMAT);
        }
 else {
          final Properties prop=new Properties();
          prop.put("String_Node_Str",atts.getValue(ATTRIBUTE_NAME_KEYREF));
          logger.logInfo(MessageUtils.getMessage("String_Node_Str",prop).toString());
        }
      }
 else       if (currentElement != null && !currentElement.isRefType) {
        final String target=keyMap.get(keyName);
        if (target != null) {
          valid=true;
          XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_SCOPE);
          XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_HREF);
          XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_TYPE);
          XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_FORMAT);
        }
 else {
        }
      }
      if (valid) {
        if (currentElement != null && MAP_TOPICREF.matches(currentElement.type)) {
          for (int index=0; index < namedNodeMap.getLength(); index++) {
            final Node node=namedNodeMap.item(index);
            if (node.getNodeType() == Node.ATTRIBUTE_NODE && !no_copy.contains(node.getNodeName())) {
              XMLUtils.removeAttribute(resAtts,node.getNodeName());
              XMLUtils.addOrSetAttribute(resAtts,node);
            }
          }
        }
 else {
          if (currentElement != null && currentElement.isRefType) {
            for (int index=0; index < namedNodeMap.getLength(); index++) {
              final Node node=namedNodeMap.item(index);
              if (node.getNodeType() == Node.ATTRIBUTE_NODE && !no_copy_topic.contains(node.getNodeName())) {
                XMLUtils.removeAttribute(resAtts,node.getNodeName());
                XMLUtils.addOrSetAttribute(resAtts,node);
              }
            }
          }
 else           if (currentElement != null && !currentElement.isRefType) {
            for (int index=0; index < namedNodeMap.getLength(); index++) {
              final Node node=namedNodeMap.item(index);
              if (node.getNodeType() == Node.ATTRIBUTE_NODE && !no_copy_topic.contains(node.getNodeName()) && !(node.getNodeName().equals(ATTRIBUTE_NAME_SCOPE) || node.getNodeName().equals(ATTRIBUTE_NAME_FORMAT) || node.getNodeName().equals(ATTRIBUTE_NAME_TYPE))) {
                XMLUtils.removeAttribute(resAtts,node.getNodeName());
                XMLUtils.addOrSetAttribute(resAtts,node);
              }
            }
          }
        }
      }
 else {
      }
    }
 else {
      final Properties prop=new Properties();
      prop.put("String_Node_Str",atts.getValue(ATTRIBUTE_NAME_KEYREF));
      logger.logInfo(MessageUtils.getMessage("String_Node_Str",prop).toString());
      ;
    }
    validKeyref.push(valid);
  }
  getContentHandler().startElement(uri,localName,name,resAtts);
}

Fixed version (ground truth):
@Override public void startElement(final String uri,final String localName,final String name,final Attributes atts) throws SAXException {
  currentElement=null;
  final String cls=atts.getValue(ATTRIBUTE_NAME_CLASS);
  for (  final KeyrefInfo k : keyrefInfos) {
    if (k.type.matches(cls)) {
      currentElement=k;
    }
  }
  final AttributesImpl resAtts=new AttributesImpl(atts);
  hasChecked=false;
  empty=true;
  boolean valid=false;
  if (atts.getIndex(ATTRIBUTE_NAME_KEYREF) == -1) {
    if (keyrefLeval != 0) {
      keyrefLeval++;
      hasSubElem.pop();
      hasSubElem.push(true);
    }
  }
 else {
    elemName.push(name);
    if (keyrefLeval != 0) {
      keyrefLevalStack.push(keyrefLeval);
      hasSubElem.pop();
      hasSubElem.push(true);
    }
    hasSubElem.push(false);
    keyrefLeval=0;
    keyrefLeval++;
    final String keyrefValue=atts.getValue(ATTRIBUTE_NAME_KEYREF);
    final int slashIndex=keyrefValue.indexOf(SLASH);
    String keyName=keyrefValue;
    String tail="String_Node_Str";
    if (slashIndex != -1) {
      keyName=keyrefValue.substring(0,slashIndex);
      tail=keyrefValue.substring(slashIndex);
    }
    final String definition=definitionMap.get(keyName);
    if (definition != null) {
      doc=keyDefToDoc(definition);
      final Element elem=doc.getDocumentElement();
      final NamedNodeMap namedNodeMap=elem.getAttributes();
      if (currentElement != null && currentElement.isRefType) {
        String target=keyMap.get(keyName);
        if (target != null && target.length() != 0) {
          String target_output=target;
          final String scopeValue=elem.getAttribute(ATTRIBUTE_NAME_SCOPE);
          if (TOPIC_IMAGE.matches(currentElement.type)) {
            valid=true;
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_SCOPE);
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_HREF);
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_TYPE);
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_FORMAT);
            target_output=FileUtils.getRelativePathFromMap(fileName,target_output);
            target_output=normalizeHrefValue(target_output,tail);
            XMLUtils.addOrSetAttribute(resAtts,currentElement.refAttr,target_output);
          }
 else           if ("String_Node_Str".equals(scopeValue) || ATTR_SCOPE_VALUE_LOCAL.equals(scopeValue)) {
            if (!(MAPGROUP_D_MAPREF.matches(cls) && FileUtils.isDITAMapFile(target.toLowerCase()))) {
              target=FileUtils.replaceExtName(target,extName);
            }
            final File topicFile=new File(FileUtils.resolveFile(tempDir,target));
            if (topicFile.exists()) {
              final String topicId=this.getFirstTopicId(topicFile);
              target_output=FileUtils.getRelativePathFromMap(filepath,new File(tempDir,target).getAbsolutePath());
              valid=true;
              XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_HREF);
              XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_SCOPE);
              XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_TYPE);
              XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_FORMAT);
              target_output=normalizeHrefValue(target_output,tail,topicId);
              XMLUtils.addOrSetAttribute(resAtts,currentElement.refAttr,target_output);
            }
 else {
            }
          }
 else {
            valid=true;
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_SCOPE);
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_HREF);
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_TYPE);
            XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_FORMAT);
            target_output=normalizeHrefValue(target_output,tail);
            XMLUtils.addOrSetAttribute(resAtts,ATTRIBUTE_NAME_HREF,target_output);
          }
        }
 else         if (target == null || target.length() == 0) {
          valid=true;
          XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_SCOPE);
          XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_HREF);
          XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_TYPE);
          XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_FORMAT);
        }
 else {
          final Properties prop=new Properties();
          prop.put("String_Node_Str",atts.getValue(ATTRIBUTE_NAME_KEYREF));
          logger.logInfo(MessageUtils.getMessage("String_Node_Str",prop).toString());
        }
      }
 else       if (currentElement != null && !currentElement.isRefType) {
        valid=true;
        XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_SCOPE);
        XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_HREF);
        XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_TYPE);
        XMLUtils.removeAttribute(resAtts,ATTRIBUTE_NAME_FORMAT);
      }
      if (valid) {
        if (currentElement != null && MAP_TOPICREF.matches(currentElement.type)) {
          for (int index=0; index < namedNodeMap.getLength(); index++) {
            final Node node=namedNodeMap.item(index);
            if (node.getNodeType() == Node.ATTRIBUTE_NODE && !no_copy.contains(node.getNodeName())) {
              XMLUtils.removeAttribute(resAtts,node.getNodeName());
              XMLUtils.addOrSetAttribute(resAtts,node);
            }
          }
        }
 else {
          if (currentElement != null && currentElement.isRefType) {
            for (int index=0; index < namedNodeMap.getLength(); index++) {
              final Node node=namedNodeMap.item(index);
              if (node.getNodeType() == Node.ATTRIBUTE_NODE && !no_copy_topic.contains(node.getNodeName())) {
                XMLUtils.removeAttribute(resAtts,node.getNodeName());
                XMLUtils.addOrSetAttribute(resAtts,node);
              }
            }
          }
 else           if (currentElement != null && !currentElement.isRefType) {
            for (int index=0; index < namedNodeMap.getLength(); index++) {
              final Node node=namedNodeMap.item(index);
              if (node.getNodeType() == Node.ATTRIBUTE_NODE && !no_copy_topic.contains(node.getNodeName()) && !(node.getNodeName().equals(ATTRIBUTE_NAME_SCOPE) || node.getNodeName().equals(ATTRIBUTE_NAME_FORMAT) || node.getNodeName().equals(ATTRIBUTE_NAME_TYPE))) {
                XMLUtils.removeAttribute(resAtts,node.getNodeName());
                XMLUtils.addOrSetAttribute(resAtts,node);
              }
            }
          }
        }
      }
 else {
      }
    }
 else {
      final Properties prop=new Properties();
      prop.put("String_Node_Str",atts.getValue(ATTRIBUTE_NAME_KEYREF));
      logger.logInfo(MessageUtils.getMessage("String_Node_Str",prop).toString());
      ;
    }
    validKeyref.push(valid);
  }
  getContentHandler().startElement(uri,localName,name,resAtts);
}