Program: 188843
Project: 188843
Buggy source:
private void createGalleryXML(LocalRepresentationObject rep,File gallery) throws IOException, MetsMetadataException {
  File originalMetsFile=new File(URI.create(rep.getRootFile().getAccessURL()));
  DigitalizedWorkMetsHelper dwMetsHelper=DigitalizedWorkMetsHelper.newInstance(originalMetsFile);
  if (gallery.exists()) {
    gallery.delete();
  }
  gallery.createNewFile();
  String galleryTemplate=new String(StreamUtils.getBytes(DW2SimpleViewer.class.getClassLoader().getResourceAsStream("String_Node_Str")));
  Mets mets=dwMetsHelper.getMets();
  DivType baseDiv=mets.getStructMapList().get(0).getDiv();
  Map<String,String> datastreamIdToCaption=new HashMap<String,String>();
  for (  RepresentationFile repFile : rep.getPartFiles()) {
    datastreamIdToCaption.put(repFile.getId(),repFile.getOriginalName());
  }
  totalImageNumber=dwMetsHelper.getFiles().size();
  currentImageNumber=1;
  String imagesXML=createImageXML(new Vector<String>(),baseDiv,datastreamIdToCaption,dwMetsHelper);
  String title;
  try {
    SimpleDescriptionObject sdo=getRodaClient().getBrowserService().getSimpleDescriptionObject(rep.getDescriptionObjectPID());
    title=sdo.getTitle();
  }
 catch (  Exception e) {
    title="String_Node_Str";
  }
  galleryTemplate=galleryTemplate.replaceAll("String_Node_Str",Matcher.quoteReplacement(title));
  galleryTemplate=galleryTemplate.replaceAll("String_Node_Str",Matcher.quoteReplacement(imagesXML));
  PrintWriter printer=new PrintWriter(new OutputStreamWriter(new FileOutputStream(gallery),"String_Node_Str"));
  printer.write(galleryTemplate);
  printer.flush();
  printer.close();
}

Fixed version (ground truth):
private void createGalleryXML(LocalRepresentationObject rep,File gallery) throws IOException, MetsMetadataException {
  File originalMetsFile=new File(URI.create(rep.getRootFile().getAccessURL()));
  DigitalizedWorkMetsHelper dwMetsHelper=DigitalizedWorkMetsHelper.newInstance(originalMetsFile);
  if (gallery.exists()) {
    gallery.delete();
  }
  gallery.createNewFile();
  String galleryTemplate=new String(StreamUtils.getBytes(DW2SimpleViewer.class.getClassLoader().getResourceAsStream("String_Node_Str")));
  Mets mets=dwMetsHelper.getMets();
  DivType baseDiv=mets.getStructMapList().get(0).getDiv();
  Map<String,String> datastreamIdToCaption=new HashMap<String,String>();
  for (  RepresentationFile repFile : rep.getPartFiles()) {
    datastreamIdToCaption.put(repFile.getId(),repFile.getOriginalName());
  }
  totalImageNumber=dwMetsHelper.getFiles().size();
  currentImageNumber=1;
  String imagesXML=createImageXML(new Vector<String>(),baseDiv,datastreamIdToCaption,dwMetsHelper);
  String title;
  try {
    SimpleDescriptionObject sdo=getRodaClient().getBrowserService().getSimpleDescriptionObject(rep.getDescriptionObjectPID());
    title=sdo.getTitle();
  }
 catch (  Exception e) {
    title="String_Node_Str";
  }
  galleryTemplate=galleryTemplate.replaceAll("String_Node_Str",Matcher.quoteReplacement(XMLUtils.xmlEncodeString(title)));
  galleryTemplate=galleryTemplate.replaceAll("String_Node_Str",Matcher.quoteReplacement(imagesXML));
  PrintWriter printer=new PrintWriter(new OutputStreamWriter(new FileOutputStream(gallery),"String_Node_Str"));
  printer.write(galleryTemplate);
  printer.flush();
  printer.close();
}