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

File.createTempFile is not adhering to the contract regarding file name lengths

    Details

    • Subcomponent:
    • Resolved In Build:
      b150
    • CPU:
      x86_64
    • OS:
      linux_ubuntu

      Description

      FULL PRODUCT VERSION :
      jdk1.7.0_80-b15

      ADDITIONAL OS VERSION INFORMATION :
      Ubuntu 14.04.2 x64

      A DESCRIPTION OF THE PROBLEM :
      A prefix and/or suffix value that is too long for a valid file name throws an exception instead of trimming to an appropriate length. According to the contract for this function:
      "To create the new file, the prefix and the suffix may first be adjusted to fit the limitations of the underlying platform. If the prefix is too long then it will be truncated, but its first three characters will always be preserved. If the suffix is too long then it too will be truncated, but if it begins with a period character ('.') then the period and the first three characters following it will always be preserved...."

      REGRESSION. Last worked in version 7u76

      ADDITIONAL REGRESSION INFORMATION:
      This was working in: jdk1.7.0_60

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run tests provided in 'Source code for an executable test case'.

      Both tests should result in a file being successfully created.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The files should be created in each case.
      ACTUAL -
      The file fails to be created, and an IOException is thrown.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Caused by: java.io.IOException: File name too long
          at java.io.UnixFileSystem.createFileExclusively(Native Method)
          at java.io.File.createTempFile(File.java:2001)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package com.foo;

      import org.testng.annotations.Test;

      import java.io.File;
      import java.io.IOException;

      @Test
      public class FileNameTest {

         @Test
         public void testFileNameLongPrefix() {
            try {
               File.createTempFile("1234567890123456789012345678901234567xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx89012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890","txt");

            } catch ( IOException e ) {
               e.printStackTrace();
            }
         }
         
         @Test
         public void testFileNameLongSuffix() {
            try {
               File.createTempFile("prefix","1234567890123456789012345678901234567xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx89012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.txt");

            } catch ( IOException e ) {
               e.printStackTrace();
            }
         }
      }
      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                bpb Brian Burkhalter
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: