{"record":{"id":"ef75f2892c5be128","repo":"apache/druid","slug":"system-property-java-io-tmpdir-is-not-set-cannot","errorCode":null,"errorMessage":"System property java.io.tmpdir is not set, cannot create temporary directories","messagePattern":"System property java\\.io\\.tmpdir is not set, cannot create temporary directories","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/FileUtils.java","lineNumber":445,"sourceCode":"   * Creates a temporary directory inside the configured temporary space (java.io.tmpdir). Similar to the method\n   * {@link com.google.common.io.Files#createTempDir()} from Guava, but has nicer error messages.\n   *\n   * @param prefix base directory name; if null/empty then this method will use \"druid\"\n   *\n   * @throws IllegalStateException if the directory could not be created\n   */\n  public static File createTempDir(@Nullable final String prefix)\n  {\n    return createTempDirInLocation(getTempDir(), prefix);\n  }\n\n  public static Path getTempDir()\n  {\n    final String parentDirectory = System.getProperty(\"java.io.tmpdir\");\n\n    if (parentDirectory == null) {\n      // Not expected.\n      throw new ISE(\"System property java.io.tmpdir is not set, cannot create temporary directories\");\n    }\n    return new File(parentDirectory).toPath();\n  }\n\n  /**\n   * Resolves {@code path} below {@code directory}, rejecting absolute paths and parent traversal that would escape it.\n   * This is intended for paths containing externally supplied identifiers.\n   */\n  public static File resolveFileWithinDirectory(final File directory, final String path)\n  {\n    final Path normalizedDirectory = directory.toPath().toAbsolutePath().normalize();\n    final Path childPath;\n    try {\n      childPath = Path.of(path);\n    }\n    catch (InvalidPathException e) {\n      throw new IAE(e, \"Path[%s] is not within directory[%s]\", path, directory);\n    }","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/FileUtils.java#L427-L463","documentation":"FileUtils.getTempDir() reads the java.io.tmpdir system property to find where temporary directories are created. If the property is not set (never expected on a normal JVM), it throws IllegalStateException because Druid cannot know where to put temp files.","triggerScenarios":"Calling getTempDir()/createTempDir() in a JVM where the java.io.tmpdir system property is null — e.g. a JVM launched with -Djava.io.tmpdir= cleared, custom/embedded JVM setups, or environments that strip system properties.","commonSituations":"Embedded Druid in application servers or test harnesses that sanitize System properties; misconfigured launch scripts setting java.io.tmpdir to empty and the property resolving unexpectedly.","solutions":["Ensure java.io.tmpdir is set: launch with -Djava.io.tmpdir=/path/to/tmp","Verify with System.out.println(System.getProperty(\"java.io.tmpdir\")) in the failing environment","If embedding Druid, initialize the property programmatically before calling createTempDir: System.setProperty(\"java.io.tmpdir\", ...)","Check that launch wrappers/agents are not clearing system properties"],"exampleFix":"// before launch\njava -jar druid.jar\n// after launch\njava -Djava.io.tmpdir=/var/tmp -jar druid.jar","handlingStrategy":"validation","validationCode":"if (System.getProperty(\"java.io.tmpdir\") == null) {\n  System.setProperty(\"java.io.tmpdir\", \"/tmp\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  File tmp = FileUtils.createTempDir();\n} catch (IllegalStateException e) {\n  System.setProperty(\"java.io.tmpdir\", System.getenv().getOrDefault(\"TMPDIR\", \"/tmp\"));\n  tmp = FileUtils.createTempDir();\n}","preventionTips":["Always launch the JVM with -Djava.io.tmpdir set explicitly","Set TMPDIR in container images and map it to java.io.tmpdir in launch scripts","Verify the property in a startup self-check","Avoid wrappers/agents that strip system properties"],"tags":["temp-directory","system-property","configuration"],"backgroundTag":"missing-env-var","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}