Details
-
Bug
-
Resolution: Fixed
-
P2
-
7u40
Backports
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8034656 | 7u65 | Unassigned | P2 | Resolved | Fixed | b01 |
JDK-8026061 | 7u60 | Dan Xu | P2 | Resolved | Fixed | b01 |
JDK-8025682 | 7u51 | Dan Xu | P2 | Resolved | Fixed | b01 |
JDK-8025474 | 7u45 | Dan Xu | P2 | Closed | Fixed | b15 |
Description
FULL PRODUCT VERSION :
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 7
Fedora
OSX
EXTRA RELEVANT SYSTEM CONFIGURATION :
nothing specific - happens on all OS
A DESCRIPTION OF THE PROBLEM :
createTempFile in past worked fine with "/foo" as input but is now failing.
REGRESSION. Last worked in version 7u40
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
This passed on all JDK's except 1.7.0_40:
package tempfile;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
String fileName= "/foo";
File target = File.createTempFile(fileName, ".jar", new File("."));
System.out.println(target.getCanonicalPath() + " " + target.exists());
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
What is expected is a random named file is created in the current directory with base name "foo".
Like "/Users/max/workspace/j1/tempfile/foo3720102051149040684.jar"
ACTUAL -
On 1.7.0_40 this breaks with the error:
Exception in thread "main" java.io.IOException: Unable to create temporary file
at java.io.File$TempDirectory.generateFile(File.java:1891)
at java.io.File.createTempFile(File.java:1979)
at tempfile.Main.main(Main.java:10)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package tempfile;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
String fileName= "/foo";
File target = File.createTempFile(fileName, ".jar", new File("."));
System.out.println(target.getCanonicalPath() + " " + target.exists());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Workaround is to change existing code to remove "/" from the passed on prefix.
But it currently breaks Eclipse, JBoss Tools and Developer Studio:
https://issues.jboss.org/browse/JBIDE-15494
https://bugs.eclipse.org/bugs/show_bug.cgi?id=417043
The fix made forJDK-8011950 at http://hg.openjdk.java.net/jdk8/tl/jdk/rev/4a66dd1d7eea fixes the issue about relative paths like ../ being used in the prefix but in doing so it broke the previous existing and already safe guarded input of "/<somename>".
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 7
Fedora
OSX
EXTRA RELEVANT SYSTEM CONFIGURATION :
nothing specific - happens on all OS
A DESCRIPTION OF THE PROBLEM :
createTempFile in past worked fine with "/foo" as input but is now failing.
REGRESSION. Last worked in version 7u40
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
This passed on all JDK's except 1.7.0_40:
package tempfile;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
String fileName= "/foo";
File target = File.createTempFile(fileName, ".jar", new File("."));
System.out.println(target.getCanonicalPath() + " " + target.exists());
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
What is expected is a random named file is created in the current directory with base name "foo".
Like "/Users/max/workspace/j1/tempfile/foo3720102051149040684.jar"
ACTUAL -
On 1.7.0_40 this breaks with the error:
Exception in thread "main" java.io.IOException: Unable to create temporary file
at java.io.File$TempDirectory.generateFile(File.java:1891)
at java.io.File.createTempFile(File.java:1979)
at tempfile.Main.main(Main.java:10)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package tempfile;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
String fileName= "/foo";
File target = File.createTempFile(fileName, ".jar", new File("."));
System.out.println(target.getCanonicalPath() + " " + target.exists());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Workaround is to change existing code to remove "/" from the passed on prefix.
But it currently breaks Eclipse, JBoss Tools and Developer Studio:
https://issues.jboss.org/browse/JBIDE-15494
https://bugs.eclipse.org/bugs/show_bug.cgi?id=417043
The fix made for
Attachments
Issue Links
- backported by
-
JDK-8025682 File.createTempFile fails if prefix is absolute path
- Resolved
-
JDK-8026061 File.createTempFile fails if prefix is absolute path
- Resolved
-
JDK-8034656 File.createTempFile fails if prefix is absolute path
- Resolved
-
JDK-8025474 File.createTempFile fails if prefix is absolute path
- Closed