Program: 188759
Project: 188759
Buggy source:
private static PreservationMetadata convertResourceToPreservationMetadata(Resource resource) throws RequestNotValidException {
  if (resource == null) {
    throw new RequestNotValidException("String_Node_Str");
  }
  StoragePath resourcePath=resource.getStoragePath();
  String filename=resourcePath.getName();
  PreservationMetadata pm=new PreservationMetadata();
  String id;
  String aipId=ModelUtils.extractAipId(resourcePath);
  String representationId=ModelUtils.extractRepresentationId(resourcePath);
  List<String> fileDirectoryPath=null;
  String fileId=null;
  PreservationMetadataType type;
  if (filename.endsWith(RodaConstants.PREMIS_AGENT_SUFFIX)) {
    id=filename.substring(0,filename.length() - RodaConstants.PREMIS_AGENT_SUFFIX.length());
    type=PreservationMetadataType.AGENT;
    aipId=null;
    representationId=null;
  }
 else   if (filename.endsWith(RodaConstants.PREMIS_EVENT_SUFFIX)) {
    id=filename.substring(0,filename.length() - RodaConstants.PREMIS_EVENT_SUFFIX.length());
    type=PreservationMetadataType.EVENT;
  }
 else   if (filename.endsWith(RodaConstants.PREMIS_FILE_SUFFIX)) {
    type=PreservationMetadataType.OBJECT_FILE;
    fileDirectoryPath=ModelUtils.extractFilePathFromRepresentationPreservationMetadata(resourcePath);
    fileId=filename.substring(0,filename.length() - RodaConstants.PREMIS_FILE_SUFFIX.length());
    id=fileId;
  }
 else   if (filename.endsWith(RodaConstants.PREMIS_REPRESENTATION_SUFFIX)) {
    id=filename.substring(0,filename.length() - RodaConstants.PREMIS_EVENT_SUFFIX.length());
    type=PreservationMetadataType.OBJECT_REPRESENTATION;
  }
 else {
    throw new RequestNotValidException("String_Node_Str" + filename);
  }
  pm.setId(id);
  pm.setAipId(aipId);
  pm.setRepresentationId(representationId);
  pm.setFileDirectoryPath(fileDirectoryPath);
  pm.setFileId(fileId);
  pm.setType(type);
  return pm;
}

Fixed version (ground truth):
private static PreservationMetadata convertResourceToPreservationMetadata(Resource resource) throws RequestNotValidException {
  if (resource == null) {
    throw new RequestNotValidException("String_Node_Str");
  }
  StoragePath resourcePath=resource.getStoragePath();
  String filename=resourcePath.getName();
  PreservationMetadata pm=new PreservationMetadata();
  String id;
  String aipId=ModelUtils.extractAipId(resourcePath);
  String representationId=ModelUtils.extractRepresentationId(resourcePath);
  List<String> fileDirectoryPath=null;
  String fileId=null;
  PreservationMetadataType type;
  if (filename.endsWith(RodaConstants.PREMIS_AGENT_SUFFIX)) {
    id=filename.substring(0,filename.length() - RodaConstants.PREMIS_AGENT_SUFFIX.length());
    type=PreservationMetadataType.AGENT;
    aipId=null;
    representationId=null;
  }
 else   if (filename.endsWith(RodaConstants.PREMIS_EVENT_SUFFIX)) {
    id=filename.substring(0,filename.length() - RodaConstants.PREMIS_EVENT_SUFFIX.length());
    type=PreservationMetadataType.EVENT;
  }
 else   if (filename.endsWith(RodaConstants.PREMIS_FILE_SUFFIX)) {
    type=PreservationMetadataType.OBJECT_FILE;
    fileDirectoryPath=ModelUtils.extractFilePathFromRepresentationPreservationMetadata(resourcePath);
    fileId=filename.substring(0,filename.length() - RodaConstants.PREMIS_FILE_SUFFIX.length());
    id=fileId;
  }
 else   if (filename.endsWith(RodaConstants.PREMIS_REPRESENTATION_SUFFIX)) {
    id=filename.substring(0,filename.length() - RodaConstants.PREMIS_REPRESENTATION_SUFFIX.length());
    type=PreservationMetadataType.OBJECT_REPRESENTATION;
  }
 else {
    throw new RequestNotValidException("String_Node_Str" + filename);
  }
  pm.setId(id);
  pm.setAipId(aipId);
  pm.setRepresentationId(representationId);
  pm.setFileDirectoryPath(fileDirectoryPath);
  pm.setFileId(fileId);
  pm.setType(type);
  return pm;
}