Program: 188433
Project: 188433
Buggy source:
public static SolrInputDocument premisToSolr(PreservationMetadataType preservationMetadataType,AIP aip,String representationUUID,String fileUUID,Binary binary) throws GenericException {
  SolrInputDocument doc;
  Map<String,String> stylesheetOpt=new HashMap<String,String>();
  stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_OBJECT_CLASS,PreservationMetadataEventClass.REPOSITORY.toString());
  if (aip != null) {
    stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_OBJECT_CLASS,PreservationMetadataEventClass.AIP.toString());
    stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_AIP_ID,aip.getId());
    if (representationUUID != null) {
      stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_REPRESENTATION_UUID,representationUUID);
      stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_OBJECT_CLASS,PreservationMetadataEventClass.REPRESENTATION.toString());
    }
    if (fileUUID != null) {
      stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_FILE_UUID,fileUUID);
      stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_OBJECT_CLASS,PreservationMetadataEventClass.FILE.toString());
    }
  }
  try {
    Reader reader=RodaUtils.applyMetadataStylesheet(binary,RodaConstants.CORE_CROSSWALKS_INGEST_OTHER,RodaConstants.PREMIS_METADATA_TYPE,RodaConstants.PREMIS_METADATA_VERSION,stylesheetOpt);
    XMLLoader loader=new XMLLoader();
    XMLStreamReader parser=XMLInputFactory.newInstance().createXMLStreamReader(reader);
    boolean parsing=true;
    doc=null;
    while (parsing) {
      int event=parser.next();
      if (event == XMLStreamConstants.END_DOCUMENT) {
        parser.close();
        parsing=false;
      }
 else       if (event == XMLStreamConstants.START_ELEMENT) {
        String currTag=parser.getLocalName();
        if ("String_Node_Str".equals(currTag)) {
          doc=loader.readDoc(parser);
        }
      }
    }
    IOUtils.closeQuietly(reader);
  }
 catch (  XMLStreamException|FactoryConfigurationError e) {
    throw new GenericException("String_Node_Str" + binary.getStoragePath(),e);
  }
  if (preservationMetadataType == PreservationMetadataType.EVENT) {
    try {
      List<LinkingIdentifier> agents=PremisV3Utils.extractAgentsFromEvent(binary);
      for (      LinkingIdentifier id : agents) {
        doc.addField(RodaConstants.PRESERVATION_EVENT_LINKING_AGENT_IDENTIFIER,JsonUtils.getJsonFromObject(id));
      }
    }
 catch (    org.roda.core.data.v2.validation.ValidationException e) {
      LOGGER.warn("String_Node_Str",e.getMessage());
    }
    try {
      List<LinkingIdentifier> sources=PremisV3Utils.extractObjectFromEvent(binary);
      for (      LinkingIdentifier id : sources) {
        doc.addField(RodaConstants.PRESERVATION_EVENT_LINKING_SOURCE_OBJECT_IDENTIFIER,JsonUtils.getJsonFromObject(id));
      }
    }
 catch (    org.roda.core.data.v2.validation.ValidationException e) {
      LOGGER.warn("String_Node_Str",e.getMessage());
    }
    try {
      List<LinkingIdentifier> outcomes=PremisV3Utils.extractObjectFromEvent(binary);
      for (      LinkingIdentifier id : outcomes) {
        doc.addField(RodaConstants.PRESERVATION_EVENT_LINKING_OUTCOME_OBJECT_IDENTIFIER,JsonUtils.getJsonFromObject(id));
      }
    }
 catch (    org.roda.core.data.v2.validation.ValidationException e) {
      LOGGER.warn("String_Node_Str",e.getMessage());
    }
    if (aip != null) {
      doc.addField(RodaConstants.STATE,aip.getState().toString());
      setPermissions(aip.getPermissions(),doc);
    }
 else {
      doc.addField(RodaConstants.STATE,AIPState.ACTIVE);
    }
  }
  doc.addField(RodaConstants.INDEX_UUID,doc.getFieldValue(RodaConstants.PRESERVATION_EVENT_ID));
  return doc;
}

Fixed version (ground truth):
public static SolrInputDocument premisToSolr(PreservationMetadataType preservationMetadataType,AIP aip,String representationUUID,String fileUUID,Binary binary) throws GenericException {
  SolrInputDocument doc;
  Map<String,String> stylesheetOpt=new HashMap<>();
  stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_OBJECT_CLASS,PreservationMetadataEventClass.REPOSITORY.toString());
  if (aip != null) {
    stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_OBJECT_CLASS,PreservationMetadataEventClass.AIP.toString());
    stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_AIP_ID,aip.getId());
    if (representationUUID != null) {
      stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_REPRESENTATION_UUID,representationUUID);
      stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_OBJECT_CLASS,PreservationMetadataEventClass.REPRESENTATION.toString());
    }
    if (fileUUID != null) {
      stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_FILE_UUID,fileUUID);
      stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_OBJECT_CLASS,PreservationMetadataEventClass.FILE.toString());
    }
  }
  Reader reader=null;
  try {
    reader=RodaUtils.applyMetadataStylesheet(binary,RodaConstants.CORE_CROSSWALKS_INGEST_OTHER,RodaConstants.PREMIS_METADATA_TYPE,RodaConstants.PREMIS_METADATA_VERSION,stylesheetOpt);
    XMLLoader loader=new XMLLoader();
    XMLStreamReader parser=XMLInputFactory.newInstance().createXMLStreamReader(reader);
    boolean parsing=true;
    doc=null;
    while (parsing) {
      int event=parser.next();
      if (event == XMLStreamConstants.END_DOCUMENT) {
        parser.close();
        parsing=false;
      }
 else       if (event == XMLStreamConstants.START_ELEMENT) {
        String currTag=parser.getLocalName();
        if ("String_Node_Str".equals(currTag)) {
          doc=loader.readDoc(parser);
        }
      }
    }
  }
 catch (  XMLStreamException|FactoryConfigurationError e) {
    throw new GenericException("String_Node_Str" + binary.getStoragePath(),e);
  }
 finally {
    IOUtils.closeQuietly(reader);
  }
  if (preservationMetadataType == PreservationMetadataType.EVENT) {
    try {
      List<LinkingIdentifier> agents=PremisV3Utils.extractAgentsFromEvent(binary);
      for (      LinkingIdentifier id : agents) {
        doc.addField(RodaConstants.PRESERVATION_EVENT_LINKING_AGENT_IDENTIFIER,JsonUtils.getJsonFromObject(id));
      }
    }
 catch (    org.roda.core.data.v2.validation.ValidationException e) {
      LOGGER.warn("String_Node_Str",e.getMessage());
    }
    try {
      List<LinkingIdentifier> sources=PremisV3Utils.extractObjectFromEvent(binary);
      for (      LinkingIdentifier id : sources) {
        doc.addField(RodaConstants.PRESERVATION_EVENT_LINKING_SOURCE_OBJECT_IDENTIFIER,JsonUtils.getJsonFromObject(id));
      }
    }
 catch (    org.roda.core.data.v2.validation.ValidationException e) {
      LOGGER.warn("String_Node_Str",e.getMessage());
    }
    try {
      List<LinkingIdentifier> outcomes=PremisV3Utils.extractObjectFromEvent(binary);
      for (      LinkingIdentifier id : outcomes) {
        doc.addField(RodaConstants.PRESERVATION_EVENT_LINKING_OUTCOME_OBJECT_IDENTIFIER,JsonUtils.getJsonFromObject(id));
      }
    }
 catch (    org.roda.core.data.v2.validation.ValidationException e) {
      LOGGER.warn("String_Node_Str",e.getMessage());
    }
    if (aip != null) {
      doc.addField(RodaConstants.STATE,aip.getState().toString());
      setPermissions(aip.getPermissions(),doc);
    }
 else {
      doc.addField(RodaConstants.STATE,AIPState.ACTIVE);
    }
  }
  doc.addField(RodaConstants.INDEX_UUID,doc.getFieldValue(RodaConstants.PRESERVATION_EVENT_ID));
  return doc;
}