{"record":{"id":"04e5a0e57028348a","repo":"apache/beam","slug":"could-not-create-the-new-requirements-file","errorCode":null,"errorMessage":"Could not create the new requirements file {updatedRequirementsFilePath}","messagePattern":"Could not create the new requirements file (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"sdks/java/transform-service/launcher/src/main/java/org/apache/beam/sdk/transformservice/launcher/TransformServiceLauncher.java","lineNumber":149,"sourceCode":"    File dependenciesDir = Paths.get(tmpDir, \"dependencies_dir\").toFile();\n    Path updatedRequirementsFilePath = Paths.get(dependenciesDir.toString(), \"requirements.txt\");\n    if (dependenciesDir.exists()) {\n      LOG.info(\"Reusing the existing dependencies directory {}\", dependenciesDir.getAbsolutePath());\n    } else {\n      LOG.info(\n          \"Creating a temporary directory for storing dependencies: {}\",\n          dependenciesDir.getAbsolutePath());\n      if (!dependenciesDir.mkdir()) {\n        throw new IOException(\n            \"Could not create a temporary directory for storing dependencies: \"\n                + dependenciesDir.getAbsolutePath());\n      }\n\n      // We create a requirements file with extra dependencies.\n      // If there are no extra dependencies, we just provide an empty requirements file.\n      File file = updatedRequirementsFilePath.toFile();\n      if (!file.createNewFile()) {\n        throw new IOException(\n            \"Could not create the new requirements file \" + updatedRequirementsFilePath);\n      }\n\n      // Updating dependencies.\n      if (pythonRequirementsFile != null) {\n        Path requirementsFilePath = Paths.get(pythonRequirementsFile);\n        List<String> updatedLines = new ArrayList<>();\n\n        try (Stream<String> lines = java.nio.file.Files.lines(requirementsFilePath)) {\n          lines.forEachOrdered(\n              line -> {\n                Path dependencyFilePath = Paths.get(line);\n                if (java.nio.file.Files.exists(dependencyFilePath)) {\n                  Path fileName = dependencyFilePath.getFileName();\n                  if (fileName == null) {\n                    throw new IllegalArgumentException(\n                        \"Could not determine the filename of the local artifact \"\n                            + dependencyFilePath);","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/transform-service/launcher/src/main/java/org/apache/beam/sdk/transformservice/launcher/TransformServiceLauncher.java#L131-L167","documentation":"Thrown when the launcher cannot create the updated Python requirements file inside the dependencies directory. File.createNewFile() returns false if the file already exists (or fails atomically), and the launcher raises this IOException. This file is required to feed extra dependencies to the transform service container via PYTHON_REQUIREMENTS_FILE_NAME, so the launch is aborted.","triggerScenarios":"Calling the launcher's startup path when updatedRequirementsFilePath.toFile().createNewFile() returns false — typically because a file already exists at that path from a previous run in a reused dependencies directory.","commonSituations":"Re-running the launcher with a persistent/reused dependencies directory where a stale requirements file from an earlier launch still exists; two launcher processes racing on the same staging directory.","solutions":["Delete stale files in the dependencies directory (or use a fresh temporary directory) before relaunching.","Ensure only one launcher instance uses the same dependencies directory at a time.","If the file legitimately exists and is current, treat it as success rather than an error path — i.e. clean the directory before startup."],"exampleFix":"// before: reused dir already contains requirements file\n// launcher: if (!file.createNewFile()) throw ...\n\n// after: caller cleans staging dir before launch\nFileUtils.deleteDirectory(dependenciesDir);\ndependenciesDir.mkdir();","handlingStrategy":"validation","validationCode":"File req = updatedRequirementsFilePath.toFile();\nif (req.exists()) {\n  // stale artifact from a previous run\n  java.nio.file.Files.delete(req.toPath());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clean (or use a fresh) dependencies directory on each launch.","Avoid running two launcher instances against the same staging directory.","Treat an existing empty requirements file as reusable rather than fatal."],"tags":["java","io","filesystem","file-creation"],"backgroundTag":"file-already-exists","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}