Program: 80589
Project: 80589
Buggy source:
@Override public NodeRef insertPDF(NodeRef targetNodeRef,Map<String,Serializable> params){
  PDDocument pdf=null;
  PDDocument insertContentPDF=null;
  InputStream is=null;
  InputStream cis=null;
  File tempDir=null;
  ContentWriter writer=null;
  NodeRef destinationNode=null;
  try {
    ContentReader targetReader=getReader(targetNodeRef);
    ContentReader insertReader=getReader((NodeRef)params.get(PARAM_TARGET_NODE));
    int insertAt=Integer.valueOf((String)params.get(PARAM_PAGE)).intValue();
    Boolean inplace=Boolean.valueOf(String.valueOf(params.get(PARAM_INPLACE)));
    is=targetReader.getContentInputStream();
    cis=insertReader.getContentInputStream();
    pdf=PDDocument.load(is);
    insertContentPDF=PDDocument.load(cis);
    Splitter splitter=new Splitter();
    List<PDDocument> pdfs=splitter.split(pdf);
    PDFMergerUtility merger=new PDFMergerUtility();
    PDDocument newDocument=new PDDocument();
    for (int i=0; i < pdfs.size(); i++) {
      if (i == insertAt - 1) {
        merger.appendDocument(newDocument,insertContentPDF);
      }
      merger.appendDocument(newDocument,(PDDocument)pdfs.get(i));
    }
    merger.setDestinationFileName(params.get(PARAM_DESTINATION_NAME).toString());
    merger.mergeDocuments();
    File alfTempDir=TempFileProvider.getTempDir();
    tempDir=new File(alfTempDir.getPath() + File.separatorChar + targetNodeRef.getId());
    tempDir.mkdir();
    String fileName=params.get(PARAM_DESTINATION_NAME).toString();
    PDDocument completePDF=newDocument;
    completePDF.save(tempDir + "String_Node_Str" + File.separatorChar+ fileName+ FILE_EXTENSION);
    try {
      completePDF.close();
      newDocument.close();
    }
 catch (    IOException e) {
      throw new AlfrescoRuntimeException(e.getMessage(),e);
    }
    for (    File file : tempDir.listFiles()) {
      try {
        if (file.isFile()) {
          destinationNode=createDestinationNode(file.getName(),(NodeRef)params.get(PARAM_DESTINATION_FOLDER),targetNodeRef,inplace);
          writer=cs.getWriter(destinationNode,ContentModel.PROP_CONTENT,true);
          writer.setEncoding(targetReader.getEncoding());
          writer.setMimetype(FILE_MIMETYPE);
          writer.putContent(file);
          file.delete();
        }
      }
 catch (      FileExistsException e) {
        throw new AlfrescoRuntimeException("String_Node_Str",e);
      }
    }
  }
 catch (  COSVisitorException e) {
    throw new AlfrescoRuntimeException(e.getMessage(),e);
  }
catch (  IOException e) {
    throw new AlfrescoRuntimeException(e.getMessage(),e);
  }
 finally {
    if (pdf != null) {
      try {
        pdf.close();
      }
 catch (      IOException e) {
        throw new AlfrescoRuntimeException(e.getMessage(),e);
      }
    }
    if (is != null) {
      try {
        is.close();
      }
 catch (      IOException e) {
        throw new AlfrescoRuntimeException(e.getMessage(),e);
      }
    }
    if (tempDir != null) {
      tempDir.delete();
    }
  }
  return destinationNode;
}

Fixed version (ground truth):
@Override public NodeRef insertPDF(NodeRef targetNodeRef,Map<String,Serializable> params){
  PDDocument pdf=null;
  PDDocument insertContentPDF=null;
  InputStream is=null;
  InputStream cis=null;
  File tempDir=null;
  ContentWriter writer=null;
  NodeRef destinationNode=null;
  try {
    ContentReader targetReader=getReader(targetNodeRef);
    ContentReader insertReader=getReader((NodeRef)params.get(PARAM_INSERT_CONTENT));
    int insertAt=Integer.valueOf((String)params.get(PARAM_PAGE)).intValue();
    Boolean inplace=Boolean.valueOf(String.valueOf(params.get(PARAM_INPLACE)));
    is=targetReader.getContentInputStream();
    cis=insertReader.getContentInputStream();
    pdf=PDDocument.load(is);
    insertContentPDF=PDDocument.load(cis);
    Splitter splitter=new Splitter();
    List<PDDocument> pdfs=splitter.split(pdf);
    PDFMergerUtility merger=new PDFMergerUtility();
    PDDocument newDocument=new PDDocument();
    for (int i=0; i < pdfs.size(); i++) {
      if (i == insertAt - 1) {
        merger.appendDocument(newDocument,insertContentPDF);
      }
      merger.appendDocument(newDocument,(PDDocument)pdfs.get(i));
    }
    merger.setDestinationFileName(params.get(PARAM_DESTINATION_NAME).toString());
    merger.mergeDocuments();
    File alfTempDir=TempFileProvider.getTempDir();
    tempDir=new File(alfTempDir.getPath() + File.separatorChar + targetNodeRef.getId());
    tempDir.mkdir();
    String fileName=params.get(PARAM_DESTINATION_NAME).toString();
    PDDocument completePDF=newDocument;
    completePDF.save(tempDir + "String_Node_Str" + File.separatorChar+ fileName+ FILE_EXTENSION);
    try {
      completePDF.close();
      newDocument.close();
    }
 catch (    IOException e) {
      throw new AlfrescoRuntimeException(e.getMessage(),e);
    }
    for (    File file : tempDir.listFiles()) {
      try {
        if (file.isFile()) {
          destinationNode=createDestinationNode(file.getName(),(NodeRef)params.get(PARAM_DESTINATION_FOLDER),targetNodeRef,inplace);
          writer=cs.getWriter(destinationNode,ContentModel.PROP_CONTENT,true);
          writer.setEncoding(targetReader.getEncoding());
          writer.setMimetype(FILE_MIMETYPE);
          writer.putContent(file);
          file.delete();
        }
      }
 catch (      FileExistsException e) {
        throw new AlfrescoRuntimeException("String_Node_Str",e);
      }
    }
  }
 catch (  COSVisitorException e) {
    throw new AlfrescoRuntimeException(e.getMessage(),e);
  }
catch (  IOException e) {
    throw new AlfrescoRuntimeException(e.getMessage(),e);
  }
 finally {
    if (pdf != null) {
      try {
        pdf.close();
      }
 catch (      IOException e) {
        throw new AlfrescoRuntimeException(e.getMessage(),e);
      }
    }
    if (is != null) {
      try {
        is.close();
      }
 catch (      IOException e) {
        throw new AlfrescoRuntimeException(e.getMessage(),e);
      }
    }
    if (tempDir != null) {
      tempDir.delete();
    }
  }
  return destinationNode;
}