Program: 80591
Project: 80591
Buggy source:
@Override public void 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;
  try {
    ContentReader targetReader=getReader(targetNodeRef);
    ContentReader insertReader=getReader((NodeRef)params.get(PARAM_TARGET_NODE));
    int insertAt=Integer.valueOf((String)params.get(PARAM_INSERT_AT_PAGE)).intValue();
    is=targetReader.getContentInputStream();
    cis=insertReader.getContentInputStream();
    pdf=PDDocument.load(is);
    insertContentPDF=PDDocument.load(cis);
    Splitter splitter=new Splitter();
    splitter.setSplitAtPage(insertAt - 1);
    List<PDDocument> pdfs=splitter.split(pdf);
    PDFMergerUtility merger=new PDFMergerUtility();
    merger.appendDocument((PDDocument)pdfs.get(0),insertContentPDF);
    merger.appendDocument((PDDocument)pdfs.get(0),(PDDocument)pdfs.get(1));
    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=getFilename(params,targetNodeRef);
    Boolean inplace=Boolean.valueOf(String.valueOf(params.get(PARAM_INPLACE)));
    PDDocument completePDF=(PDDocument)pdfs.get(0);
    completePDF.save(tempDir + "String_Node_Str" + File.separatorChar+ fileName+ FILE_EXTENSION);
    try {
      completePDF.close();
    }
 catch (    IOException e) {
      throw new AlfrescoRuntimeException(e.getMessage(),e);
    }
    for (    File file : tempDir.listFiles()) {
      try {
        if (file.isFile()) {
          NodeRef 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();
    }
  }
}

Fixed version (ground truth):
@Override public void 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;
  try {
    ContentReader targetReader=getReader(targetNodeRef);
    ContentReader insertReader=getReader((NodeRef)params.get(PARAM_TARGET_NODE));
    int insertAt=Integer.valueOf((String)params.get(PARAM_INSERT_AT_PAGE)).intValue();
    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();
    Boolean inplace=Boolean.valueOf(String.valueOf(params.get(PARAM_INPLACE)));
    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()) {
          NodeRef 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();
    }
  }
}