Program: 100643
Project: 100643
Buggy source:
private Attributes processElement(final Attributes atts){
  final AttributesImpl resAtts=new AttributesImpl(atts);
  boolean valid=false;
  for (  final Map.Entry<String,String> attrPair : currentElement.attrs.entrySet()) {
    final String keyrefAttr=attrPair.getKey();
    final String refAttr=attrPair.getValue();
    final String keyrefValue=atts.getValue(keyrefAttr);
    if (keyrefValue != null) {
      final int slashIndex=keyrefValue.indexOf(SLASH);
      String keyName=keyrefValue;
      String elementId="String_Node_Str";
      if (slashIndex != -1) {
        keyName=keyrefValue.substring(0,slashIndex);
        elementId=keyrefValue.substring(slashIndex);
      }
      keyDef=definitionMap.get(keyName);
      final Element elem=keyDef != null ? keyDef.element : null;
      if (keyDef != null) {
        if (currentElement != null) {
          final NamedNodeMap attrs=elem.getAttributes();
          final URI target=keyDef != null ? keyDef.href : null;
          if (target != null && !target.toString().isEmpty()) {
            if (TOPIC_IMAGE.matches(currentElement.type)) {
              valid=true;
              final URI targetOutput=normalizeHrefValue(URLUtils.getRelativePath(currentFile,job.tempDir.toURI().resolve(target)),elementId);
              XMLUtils.addOrSetAttribute(resAtts,refAttr,targetOutput.toString());
            }
 else             if (isLocalDita(elem)) {
              final File topicFile=toFile(job.tempDir.toURI().resolve(stripFragment(target)));
              valid=true;
              final String topicId=getFirstTopicId(topicFile);
              final URI targetOutput=normalizeHrefValue(URLUtils.getRelativePath(currentFile,job.tempDir.toURI().resolve(target)),elementId,topicId);
              XMLUtils.addOrSetAttribute(resAtts,refAttr,targetOutput.toString());
              if (!ATTR_PROCESSING_ROLE_VALUE_RESOURCE_ONLY.equals(atts.getValue(ATTRIBUTE_NAME_PROCESSING_ROLE))) {
                final URI f=currentFile.resolve(targetOutput);
                normalProcessingRoleTargets.add(f);
              }
            }
 else {
              valid=true;
              final URI targetOutput=normalizeHrefValue(target,elementId);
              XMLUtils.addOrSetAttribute(resAtts,refAttr,targetOutput.toString());
            }
          }
 else           if (target == null || target.toString().isEmpty()) {
            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 MessageBean m=definitionMap.name == null ? MessageUtils.getInstance().getMessage("String_Node_Str",atts.getValue(ATTRIBUTE_NAME_KEYREF)) : MessageUtils.getInstance().getMessage("String_Node_Str",atts.getValue(ATTRIBUTE_NAME_KEYREF),definitionMap.name);
            logger.info(m.setLocation(atts).toString());
          }
          if (valid) {
            if (MAP_TOPICREF.matches(currentElement.type)) {
              for (int index=0; index < attrs.getLength(); index++) {
                final Attr attr=(Attr)attrs.item(index);
                if (!no_copy.contains(attr.getNodeName())) {
                  XMLUtils.removeAttribute(resAtts,attr.getNodeName());
                  XMLUtils.addOrSetAttribute(resAtts,attr);
                }
              }
            }
 else {
              for (int index=0; index < attrs.getLength(); index++) {
                final Attr attr=(Attr)attrs.item(index);
                if (!no_copy_topic.contains(attr.getNodeName()) && (attr.getNodeName().equals(refAttr) || resAtts.getIndex(attr.getNodeName()) == -1)) {
                  XMLUtils.removeAttribute(resAtts,attr.getNodeName());
                  XMLUtils.addOrSetAttribute(resAtts,attr);
                }
              }
            }
          }
        }
      }
 else {
        final MessageBean m=definitionMap.name == null ? MessageUtils.getInstance().getMessage("String_Node_Str",atts.getValue(ATTRIBUTE_NAME_KEYREF)) : MessageUtils.getInstance().getMessage("String_Node_Str",atts.getValue(ATTRIBUTE_NAME_KEYREF),definitionMap.name);
        logger.info(m.setLocation(atts).toString());
      }
      validKeyref.push(valid);
    }
  }
  return resAtts;
}

Fixed version (ground truth):
private Attributes processElement(final Attributes atts){
  final AttributesImpl resAtts=new AttributesImpl(atts);
  boolean valid=false;
  for (  final Map.Entry<String,String> attrPair : currentElement.attrs.entrySet()) {
    final String keyrefAttr=attrPair.getKey();
    final String refAttr=attrPair.getValue();
    final String keyrefValue=atts.getValue(keyrefAttr);
    if (keyrefValue != null) {
      final int slashIndex=keyrefValue.indexOf(SLASH);
      String keyName=keyrefValue;
      String elementId="String_Node_Str";
      if (slashIndex != -1) {
        keyName=keyrefValue.substring(0,slashIndex);
        elementId=keyrefValue.substring(slashIndex);
      }
      keyDef=definitionMap.get(keyName);
      final Element elem=keyDef != null ? keyDef.element : null;
      if (keyDef != null) {
        if (currentElement != null) {
          final NamedNodeMap attrs=elem.getAttributes();
          final URI href=keyDef.href;
          if (href != null && !href.toString().isEmpty()) {
            if (TOPIC_IMAGE.matches(currentElement.type)) {
              valid=true;
              final URI targetOutput=normalizeHrefValue(URLUtils.getRelativePath(currentFile,job.tempDir.toURI().resolve(href)),elementId);
              XMLUtils.addOrSetAttribute(resAtts,refAttr,targetOutput.toString());
            }
 else             if (isLocalDita(elem) && keyDef.source != null) {
              final File topicFile=toFile(currentFile.resolve(stripFragment(keyDef.source.resolve(href))));
              valid=true;
              final String topicId=getFirstTopicId(topicFile);
              final URI targetOutput=normalizeHrefValue(URLUtils.getRelativePath(currentFile,topicFile.toURI()),elementId,topicId);
              XMLUtils.addOrSetAttribute(resAtts,refAttr,targetOutput.toString());
              if (!ATTR_PROCESSING_ROLE_VALUE_RESOURCE_ONLY.equals(atts.getValue(ATTRIBUTE_NAME_PROCESSING_ROLE))) {
                final URI f=currentFile.resolve(targetOutput);
                normalProcessingRoleTargets.add(f);
              }
            }
 else {
              valid=true;
              final URI targetOutput=normalizeHrefValue(href,elementId);
              XMLUtils.addOrSetAttribute(resAtts,refAttr,targetOutput.toString());
            }
          }
 else           if (href == null || href.toString().isEmpty()) {
            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 MessageBean m=definitionMap.name == null ? MessageUtils.getInstance().getMessage("String_Node_Str",atts.getValue(ATTRIBUTE_NAME_KEYREF)) : MessageUtils.getInstance().getMessage("String_Node_Str",atts.getValue(ATTRIBUTE_NAME_KEYREF),definitionMap.name);
            logger.info(m.setLocation(atts).toString());
          }
          if (valid) {
            if (MAP_TOPICREF.matches(currentElement.type)) {
              for (int index=0; index < attrs.getLength(); index++) {
                final Attr attr=(Attr)attrs.item(index);
                if (!no_copy.contains(attr.getNodeName())) {
                  XMLUtils.removeAttribute(resAtts,attr.getNodeName());
                  XMLUtils.addOrSetAttribute(resAtts,attr);
                }
              }
            }
 else {
              for (int index=0; index < attrs.getLength(); index++) {
                final Attr attr=(Attr)attrs.item(index);
                if (!no_copy_topic.contains(attr.getNodeName()) && (attr.getNodeName().equals(refAttr) || resAtts.getIndex(attr.getNodeName()) == -1)) {
                  XMLUtils.removeAttribute(resAtts,attr.getNodeName());
                  XMLUtils.addOrSetAttribute(resAtts,attr);
                }
              }
            }
          }
        }
      }
 else {
        final MessageBean m=definitionMap.name == null ? MessageUtils.getInstance().getMessage("String_Node_Str",atts.getValue(ATTRIBUTE_NAME_KEYREF)) : MessageUtils.getInstance().getMessage("String_Node_Str",atts.getValue(ATTRIBUTE_NAME_KEYREF),definitionMap.name);
        logger.info(m.setLocation(atts).toString());
      }
      validKeyref.push(valid);
    }
  }
  return resAtts;
}