From 41f16fa27bd7f51d5623146d86a0f29260e4cab7 Mon Sep 17 00:00:00 2001 From: "Flavio S. Glock" Date: Fri, 8 May 2026 14:14:56 +0200 Subject: [PATCH] fix: File::Temp Java backend uses cwd for pathless templates Perl's File::Temp::tempfile($template) creates files in the current directory when the template has no directory component. The Java implementation incorrectly used java.io.tmpdir / TMPDIR for that case, so relative globs (e.g. Config::JSON's glob '*.include.conf') did not see include files. Align createTempFile/createTempDir with stock Perl. Fixes jcpan -t Config::JSON (t/Wildcard.t). Generated with [Cursor](https://cursor.com) Co-Authored-By: Cursor --- .../org/perlonjava/runtime/perlmodule/FileTemp.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/perlonjava/runtime/perlmodule/FileTemp.java b/src/main/java/org/perlonjava/runtime/perlmodule/FileTemp.java index cbf763868..9fd3095a5 100644 --- a/src/main/java/org/perlonjava/runtime/perlmodule/FileTemp.java +++ b/src/main/java/org/perlonjava/runtime/perlmodule/FileTemp.java @@ -205,8 +205,9 @@ private static RuntimeList createTempFile(String template, String suffix, boolea String namePrefix; if (prefix.isEmpty()) { - // No directory specified, use temp dir - dir = Paths.get(getTempDir()); + // Template is only trailing X's (e.g. "XXXXXX") with no path: Perl creates + // the file in the current working directory, not File::Spec->tmpdir. + dir = Paths.get(System.getProperty("user.dir")); namePrefix = ""; } else if (prefix.endsWith("/") || prefix.endsWith("\\")) { // Prefix is a directory path with trailing separator @@ -221,7 +222,8 @@ private static RuntimeList createTempFile(String template, String suffix, boolea templatePath.getFileName().toString() : ""; if (dir == null) { - dir = Paths.get(getTempDir()); + // Relative name prefix only (e.g. "fooXXXXXX"): parent is cwd, not tmpdir. + dir = Paths.get(System.getProperty("user.dir")); } } @@ -301,8 +303,7 @@ private static Path createTempDir(String template) { String namePrefix; if (prefix.isEmpty()) { - // No directory specified, use temp dir - parentDir = Paths.get(getTempDir()); + parentDir = Paths.get(System.getProperty("user.dir")); namePrefix = ""; } else if (prefix.endsWith("/") || prefix.endsWith("\\")) { // Prefix is a directory path with trailing separator @@ -316,7 +317,7 @@ private static Path createTempDir(String template) { templatePath.getFileName().toString() : ""; if (parentDir == null) { - parentDir = Paths.get(getTempDir()); + parentDir = Paths.get(System.getProperty("user.dir")); } }