Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8025128

File.createTempFile fails if prefix is absolute path

    Details

    • Subcomponent:
    • Introduced In Version:
    • Resolved In Build:
      b112
    • OS:
      windows_7
    • Verification:
      Verified

      Backports

        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 for JDK-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>".

          Activity

          Hide
          alanb Alan Bateman added a comment - - edited
          Dan is looking into this to see if a fix is required (specifying the usage as "/foo" is of course not the intended usage of this API but the validation in previous releases didn't catch it).
          Show
          alanb Alan Bateman added a comment - - edited Dan is looking into this to see if a fix is required (specifying the usage as "/foo" is of course not the intended usage of this API but the validation in previous releases didn't catch it).
          Hide
          rlewis Roger Lewis added a comment - - edited
          One other software packages are facing this bug:
          Pentaho: http://forums.pentaho.com/showthread.php?149302-Error-installing-timeseriesForecasting-plugin
          (removed Alfresco, not applicable)
          Show
          rlewis Roger Lewis added a comment - - edited One other software packages are facing this bug: Pentaho: http://forums.pentaho.com/showthread.php?149302-Error-installing-timeseriesForecasting-plugin (removed Alfresco, not applicable)
          Hide
          rlewis Roger Lewis added a comment -
          You are correct, let me remove that from my comment.
          Show
          rlewis Roger Lewis added a comment - You are correct, let me remove that from my comment.
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/754db1268be1
          User: dxu
          Date: 2013-09-28 00:10:19 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/754db1268be1 User: dxu Date: 2013-09-28 00:10:19 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/754db1268be1
          User: lana
          Date: 2013-10-11 18:24:46 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/754db1268be1 User: lana Date: 2013-10-11 18:24:46 +0000

            People

            • Assignee:
              dxu Dan Xu (Inactive)
              Reporter:
              ndcosta Nelson Dcosta
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: