Program: 188315
Project: 188315
Buggy source:
public static void changeRepresentationType(User user,SelectedItems<IndexedRepresentation> selected,String newType,String details) throws GenericException, AuthorizationDeniedException, RequestNotValidException, NotFoundException {
  Locale locale=ServerTools.parseLocale(RodaConstants.DEFAULT_EVENT_LOCALE);
  Messages messages=RodaCoreFactory.getI18NMessages(locale);
  String eventDescription=messages.getTranslation(RodaConstants.EVENT_UPDATE_ON_REPOSITORY);
  List<String> representationIds=consolidate(user,IndexedRepresentation.class,selected);
  ModelService model=RodaCoreFactory.getModelService();
  IndexService index=RodaCoreFactory.getIndexService();
  Filter filter=new Filter();
  filter.add(new OneOfManyFilterParameter(RodaConstants.INDEX_UUID,representationIds));
  IndexResult<IndexedRepresentation> reps=index.find(IndexedRepresentation.class,filter,Sorter.NONE,new Sublist(0,representationIds.size()),Arrays.asList(RodaConstants.REPRESENTATION_ID,RodaConstants.REPRESENTATION_TYPE,RodaConstants.REPRESENTATION_AIP_ID));
  for (  IndexedRepresentation irep : reps.getResults()) {
    String oldType=irep.getType();
    List<LinkingIdentifier> sources=new ArrayList<>();
    sources.add(PluginHelper.getLinkingIdentifier(irep.getAipId(),irep.getId(),RodaConstants.PRESERVATION_LINKING_OBJECT_SOURCE));
    try {
      model.updateRepresentationType(irep.getAipId(),irep.getId(),newType);
      String outcomeText=messages.getTranslationWithArgs(RodaConstants.EVENT_CHANGE_TYPE_REPRESENTATION_SUCCESS,irep.getId(),oldType,newType);
      model.createEvent(irep.getAipId(),irep.getId(),null,null,PreservationEventType.UPDATE,eventDescription,sources,null,PluginState.SUCCESS,outcomeText,details,user.getName(),true);
    }
 catch (    RequestNotValidException|NotFoundException|GenericException|AuthorizationDeniedException e) {
      String outcomeText=messages.getTranslationWithArgs(RodaConstants.EVENT_CHANGE_TYPE_REPRESENTATION_FAILURE,irep.getId(),oldType,newType);
      model.createEvent(irep.getAipId(),irep.getId(),null,null,PreservationEventType.UPDATE,eventDescription,sources,null,PluginState.FAILURE,outcomeText,details,user.getName(),true);
      throw e;
    }
  }
  index.commit(IndexedRepresentation.class);
}

Fixed version (ground truth):
public static void changeRepresentationType(User user,SelectedItems<IndexedRepresentation> selected,String newType,String details) throws GenericException, AuthorizationDeniedException, RequestNotValidException, NotFoundException {
  Locale locale=ServerTools.parseLocale(RodaConstants.DEFAULT_EVENT_LOCALE);
  Messages messages=RodaCoreFactory.getI18NMessages(locale);
  String eventDescription=messages.getTranslation(RodaConstants.EVENT_UPDATE_ON_REPOSITORY);
  List<String> representationIds=consolidate(user,IndexedRepresentation.class,selected);
  ModelService model=RodaCoreFactory.getModelService();
  IndexService index=RodaCoreFactory.getIndexService();
  Filter filter=new Filter();
  filter.add(new OneOfManyFilterParameter(RodaConstants.INDEX_UUID,representationIds));
  IndexResult<IndexedRepresentation> reps=index.find(IndexedRepresentation.class,filter,Sorter.NONE,new Sublist(0,representationIds.size()),Arrays.asList(RodaConstants.REPRESENTATION_ID,RodaConstants.REPRESENTATION_TYPE,RodaConstants.REPRESENTATION_AIP_ID));
  for (  IndexedRepresentation irep : reps.getResults()) {
    String oldType=irep.getType();
    List<LinkingIdentifier> sources=new ArrayList<>();
    sources.add(PluginHelper.getLinkingIdentifier(irep.getAipId(),irep.getId(),RodaConstants.PRESERVATION_LINKING_OBJECT_SOURCE));
    try {
      model.updateRepresentationType(irep.getAipId(),irep.getId(),newType);
      index.commit(IndexedRepresentation.class);
      String outcomeText=messages.getTranslationWithArgs(RodaConstants.EVENT_CHANGE_TYPE_REPRESENTATION_SUCCESS,irep.getId(),oldType,newType);
      model.createEvent(irep.getAipId(),irep.getId(),null,null,PreservationEventType.UPDATE,eventDescription,sources,null,PluginState.SUCCESS,outcomeText,details,user.getName(),true);
    }
 catch (    RequestNotValidException|NotFoundException|GenericException|AuthorizationDeniedException e) {
      String outcomeText=messages.getTranslationWithArgs(RodaConstants.EVENT_CHANGE_TYPE_REPRESENTATION_FAILURE,irep.getId(),oldType,newType);
      model.createEvent(irep.getAipId(),irep.getId(),null,null,PreservationEventType.UPDATE,eventDescription,sources,null,PluginState.FAILURE,outcomeText,details,user.getName(),true);
      throw e;
    }
  }
}