Program: 47402
Project: 47402
Buggy source:
/** 
 * Copy selected list of files to a new specified location
 * @param pathId (colon separated path for the repository file)
 * @param mode (MODE_OVERWITE or MODE_NO_OVERWRITE)
 * @param params (List of files to be copied)
 * @return
 */
@PUT @Path("String_Node_Str") @Consumes({TEXT_PLAIN}) public Response copyFiles(@PathParam("String_Node_Str") String pathId,@QueryParam("String_Node_Str") Integer mode,String params){
  if (mode == null) {
    mode=MODE_RENAME;
  }
  if (!getPolicy().isAllowed(RepositoryCreateAction.NAME)) {
    return Response.status(FORBIDDEN).build();
  }
  try {
    String path=idToPath(pathId);
    RepositoryFile destDir=getRepository().getFile(path);
    String[] sourceFileIds=params.split("String_Node_Str");
    if (mode == MODE_OVERWRITE || mode == MODE_NO_OVERWRITE) {
      for (      String sourceFileId : sourceFileIds) {
        RepositoryFile sourceFile=getRepository().getFileById(sourceFileId);
        if (destDir != null && destDir.isFolder() && sourceFile != null && !sourceFile.isFolder()) {
          String fileName=sourceFile.getName();
          String sourcePath=sourceFile.getPath().substring(0,sourceFile.getPath().lastIndexOf(PATH_SEPARATOR));
          if (!sourcePath.equals(destDir.getPath())) {
            IRepositoryFileData data=getData(sourceFile);
            RepositoryFileAcl acl=getRepository().getAcl(sourceFileId);
            RepositoryFile destFile=getRepository().getFile(destDir.getPath() + PATH_SEPARATOR + fileName);
            if (destFile == null) {
              RepositoryFile duplicateFile=new RepositoryFile.Builder(fileName).hidden(sourceFile.isHidden()).versioned(sourceFile.isVersioned()).build();
              final RepositoryFile repositoryFile=getRepository().createFile(destDir.getId(),duplicateFile,data,acl,null);
              getRepository().setFileMetadata(repositoryFile.getId(),getRepository().getFileMetadata(sourceFileId));
            }
 else             if (mode == MODE_OVERWRITE) {
              RepositoryFileDto destFileDto=RepositoryFileAdapter.toFileDto(destFile,null,false);
              destFileDto.setHidden(sourceFile.isHidden());
              destFile=RepositoryFileAdapter.toFile(destFileDto);
              final RepositoryFile repositoryFile=getRepository().updateFile(destFile,data,null);
              getRepository().updateAcl(acl);
              getRepository().setFileMetadata(repositoryFile.getId(),getRepository().getFileMetadata(sourceFileId));
            }
          }
        }
      }
    }
 else {
      for (      String sourceFileId : sourceFileIds) {
        RepositoryFile sourceFile=getRepository().getFileById(sourceFileId);
        if (destDir != null && destDir.isFolder() && sourceFile != null && !sourceFile.isFolder()) {
          String fileName=sourceFile.getName();
          String copyText="String_Node_Str";
          String rootCopyText="String_Node_Str";
          String nameNoExtension=fileName.substring(0,fileName.lastIndexOf('.') == -1 ? fileName.length() : fileName.lastIndexOf('.'));
          String extension=fileName.substring(fileName.lastIndexOf('.'));
          RepositoryFileDto testFile=getRepoWs().getFile(path + PATH_SEPARATOR + nameNoExtension+ extension);
          if (testFile != null) {
            if (!nameNoExtension.endsWith(Messages.getInstance().getString("String_Node_Str"))) {
              copyText=rootCopyText=Messages.getInstance().getString("String_Node_Str");
              fileName=nameNoExtension + copyText + extension;
              testFile=getRepoWs().getFile(path + PATH_SEPARATOR + fileName);
            }
          }
          Integer nameCount=1;
          while (testFile != null) {
            nameCount++;
            copyText=rootCopyText + Messages.getInstance().getString("String_Node_Str",nameCount);
            fileName=nameNoExtension + copyText + extension;
            testFile=getRepoWs().getFile(path + PATH_SEPARATOR + fileName);
          }
          IRepositoryFileData data=getData(sourceFile);
          RepositoryFileAcl acl=getRepository().getAcl(sourceFileId);
          RepositoryFile duplicateFile=null;
          if (!sourceFile.getName().equals(sourceFile.getTitle())) {
            duplicateFile=new RepositoryFile.Builder(fileName).title(RepositoryFile.DEFAULT_LOCALE,sourceFile.getTitle() + copyText).hidden(sourceFile.isHidden()).versioned(sourceFile.isVersioned()).build();
          }
 else {
            duplicateFile=new RepositoryFile.Builder(fileName).hidden(sourceFile.isHidden()).build();
          }
          final RepositoryFile repositoryFile=getRepository().createFile(destDir.getId(),duplicateFile,data,acl,null);
          getRepository().setFileMetadata(repositoryFile.getId(),getRepository().getFileMetadata(sourceFileId));
        }
      }
    }
  }
 catch (  Throwable t) {
    t.printStackTrace();
    return Response.serverError().entity(new SafeHtmlBuilder().appendEscapedLines(t.getLocalizedMessage()).toSafeHtml().asString()).build();
  }
  return Response.ok().build();
}

Fixed version (ground truth):
/** 
 * Copy selected list of files to a new specified location
 * @param pathId (colon separated path for the repository file)
 * @param mode (MODE_OVERWITE or MODE_NO_OVERWRITE)
 * @param params (List of files to be copied)
 * @return
 */
@PUT @Path("String_Node_Str") @Consumes({TEXT_PLAIN}) public Response copyFiles(@PathParam("String_Node_Str") String pathId,@QueryParam("String_Node_Str") Integer mode,String params){
  if (mode == null) {
    mode=MODE_RENAME;
  }
  if (!getPolicy().isAllowed(RepositoryCreateAction.NAME)) {
    return Response.status(FORBIDDEN).build();
  }
  try {
    String path=idToPath(pathId);
    RepositoryFile destDir=getRepository().getFile(path);
    String[] sourceFileIds=params.split("String_Node_Str");
    if (mode == MODE_OVERWRITE || mode == MODE_NO_OVERWRITE) {
      for (      String sourceFileId : sourceFileIds) {
        RepositoryFile sourceFile=getRepository().getFileById(sourceFileId);
        if (destDir != null && destDir.isFolder() && sourceFile != null && !sourceFile.isFolder()) {
          String fileName=sourceFile.getName();
          String sourcePath=sourceFile.getPath().substring(0,sourceFile.getPath().lastIndexOf(PATH_SEPARATOR));
          if (!sourcePath.equals(destDir.getPath())) {
            IRepositoryFileData data=getData(sourceFile);
            RepositoryFileAcl acl=getRepository().getAcl(sourceFileId);
            RepositoryFile destFile=getRepository().getFile(destDir.getPath() + PATH_SEPARATOR + fileName);
            if (destFile == null) {
              RepositoryFile duplicateFile=new RepositoryFile.Builder(fileName).hidden(sourceFile.isHidden()).versioned(sourceFile.isVersioned()).build();
              final RepositoryFile repositoryFile=getRepository().createFile(destDir.getId(),duplicateFile,data,acl,null);
              getRepository().setFileMetadata(repositoryFile.getId(),getRepository().getFileMetadata(sourceFileId));
            }
 else             if (mode == MODE_OVERWRITE) {
              RepositoryFileDto destFileDto=RepositoryFileAdapter.toFileDto(destFile,null,false);
              destFileDto.setHidden(sourceFile.isHidden());
              destFile=RepositoryFileAdapter.toFile(destFileDto);
              final RepositoryFile repositoryFile=getRepository().updateFile(destFile,data,null);
              getRepository().updateAcl(acl);
              getRepository().setFileMetadata(repositoryFile.getId(),getRepository().getFileMetadata(sourceFileId));
            }
          }
        }
      }
    }
 else {
      for (      String sourceFileId : sourceFileIds) {
        RepositoryFile sourceFile=getRepository().getFileById(sourceFileId);
        if (destDir != null && destDir.isFolder() && sourceFile != null && !sourceFile.isFolder()) {
          String fileName=sourceFile.getName();
          String copyText="String_Node_Str";
          String rootCopyText="String_Node_Str";
          String nameNoExtension=fileName;
          String extension="String_Node_Str";
          int indexOfDot=fileName.lastIndexOf('.');
          if (!(indexOfDot == -1)) {
            nameNoExtension=fileName.substring(0,indexOfDot);
            extension=fileName.substring(indexOfDot);
          }
          RepositoryFileDto testFile=getRepoWs().getFile(path + PATH_SEPARATOR + nameNoExtension+ extension);
          if (testFile != null) {
            if (!nameNoExtension.endsWith(Messages.getInstance().getString("String_Node_Str"))) {
              copyText=rootCopyText=Messages.getInstance().getString("String_Node_Str");
              fileName=nameNoExtension + copyText + extension;
              testFile=getRepoWs().getFile(path + PATH_SEPARATOR + fileName);
            }
          }
          Integer nameCount=1;
          while (testFile != null) {
            nameCount++;
            copyText=rootCopyText + Messages.getInstance().getString("String_Node_Str",nameCount);
            fileName=nameNoExtension + copyText + extension;
            testFile=getRepoWs().getFile(path + PATH_SEPARATOR + fileName);
          }
          IRepositoryFileData data=getData(sourceFile);
          RepositoryFileAcl acl=getRepository().getAcl(sourceFileId);
          RepositoryFile duplicateFile=null;
          if (!sourceFile.getName().equals(sourceFile.getTitle())) {
            duplicateFile=new RepositoryFile.Builder(fileName).title(RepositoryFile.DEFAULT_LOCALE,sourceFile.getTitle() + copyText).hidden(sourceFile.isHidden()).versioned(sourceFile.isVersioned()).build();
          }
 else {
            duplicateFile=new RepositoryFile.Builder(fileName).hidden(sourceFile.isHidden()).build();
          }
          final RepositoryFile repositoryFile=getRepository().createFile(destDir.getId(),duplicateFile,data,acl,null);
          getRepository().setFileMetadata(repositoryFile.getId(),getRepository().getFileMetadata(sourceFileId));
        }
      }
    }
  }
 catch (  Throwable t) {
    t.printStackTrace();
    return Response.serverError().entity(new SafeHtmlBuilder().appendEscapedLines(t.getLocalizedMessage()).toSafeHtml().asString()).build();
  }
  return Response.ok().build();
}