{"record":{"id":"749aa72fd5c262a7","repo":"SonarSource/sonarqube","slug":"can-not-move-file-to","errorCode":null,"errorMessage":"Can not move file  to ","messagePattern":"Can not move file  to ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/util/Files2.java","lineNumber":126,"sourceCode":"  public void moveFileOrThrowIOE(File from, File to) throws IOException {\n    org.apache.commons.io.FileUtils.moveFile(from, to);\n  }\n\n  /**\n   * Like {@link #moveFileOrThrowIOE(File, File)} but wraps {@link IOException}\n   * into {@link IllegalStateException}.\n   *\n   * @param from the file to be moved\n   * @param to the destination file\n   * @throws IllegalStateException if the destination file exists\n   * @throws IllegalStateException if source or destination is invalid\n   * @throws IllegalStateException if an IO error occurs moving the file\n   */\n  public void moveFile(File from, File to) {\n    try {\n      moveFileOrThrowIOE(from, to);\n    } catch (IOException e) {\n      throw new IllegalStateException(\"Can not move file \" + from + \" to \" + to, e);\n    }\n  }\n\n  /**\n   * Opens a {@link FileOutputStream} for the specified file, checking and\n   * creating the parent directory if it does not exist.\n   * <p>\n   * The parent directory will be created if it does not exist.\n   * The file will be created if it does not exist.\n   *\n   * @param file  the file to open for output, must not be {@code null}\n   * @param append if {@code true}, then bytes will be added to the\n   * end of the file rather than overwriting\n   * @return a new {@link FileOutputStream} for the specified file\n   * @throws IOException if the specified file is a directory\n   * @throws IOException if the file can not be written to\n   * @throws IOException if a parent directory can not be created\n   */","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/util/Files2.java#L108-L144","documentation":"Files2.moveFile(File from, File to) moves a file, translating any IOException from moveFileOrThrowIOE into an IllegalStateException with the message \"Can not move file <from> to <to>\". It is thrown whenever the filesystem cannot complete the move (rename) operation.","triggerScenarios":"moveFileOrThrowIOE throws IOException — source missing or unreadable, target exists as a directory, target directory missing or unwritable, cross-device move that fails, or the file is locked by another process.","commonSituations":"Moving dump files between different mount points where rename fails; target directory not created beforehand; another CE process holding the file open; running out of space when the move falls back to copy+delete.","solutions":["Ensure the source file exists and the destination's parent directory exists and is writable","Keep source and destination on the same filesystem so an atomic rename is possible","Check for other processes locking either file and stop them","Verify free disk space on the destination volume"],"exampleFix":"// before\nfiles2.moveFile(report, new File(\"/other-volume/out/report.bin\"));\n// after\nFile destDir = new File(\"/other-volume/out\");\nif (destDir.isDirectory() || destDir.mkdirs()) {\n  files2.moveFile(report, new File(destDir, \"report.bin\"));\n}","handlingStrategy":"validation","validationCode":"if (!from.isFile()) throw new IllegalStateException(\"Source missing: \" + from);\nFile parent = to.getParentFile();\nif (parent != null && !parent.isDirectory() && !parent.mkdirs()) {\n  throw new IllegalStateException(\"Cannot create dest dir: \" + parent);\n}","typeGuard":null,"tryCatchPattern":"try {\n  files2.moveFile(from, to);\n} catch (IllegalStateException e) {\n  LOGGER.error(\"Move {} -> {} failed: {}\", from, to, e.getCause(), e);\n  // fall back to copy + delete if cross-device\n}","preventionTips":["Keep source and destination on the same filesystem","Create destination directories before moving","Verify free space and permissions on both paths","Avoid concurrent processes touching the same files"],"tags":["filesystem","move","io","permissions"],"backgroundTag":"file-move-failed","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}