RFR: JDK-8013827 and JDK-8011950, , java.io.File.createTempFile enters infinite loop when passed invalid data

Alan Bateman Alan.Bateman at oracle.com
Wed May 29 11:54:06 UTC 2013

On 28/05/2013 19:39, Dan Xu wrote:
> Hi All,
> When File.createTempFile() is called with some special parameters, it 
> runs into infiniteloop and hangs. It is because it does not always 
> mean a file exists when the method, createFileExclusively(), returns 
> false. This fix is going to solve such issues reported in JDK-8013827 
> and JDK-8011950.And I also added some testcases to verify it.
> webrev: http://cr.openjdk.java.net/~dxu/8013827/webrev.00/
> bug: http://bugs.sun.com/view_bug.do?bug_id=8011950
> -Dan
Thanks for taking this one.

The changes mean that IAE is now thrown for cases where it wasn't thrown 
previously and I'm wondering if this is worth doing. It might be simpler 
to just throw IOException on the grounds that creating the file will fail.

One other thing to consider is that "\" is a valid name of a file on 
some platforms. I suspect you'll need to delegate to the FileSystem to 
check the suffix/prefix. Alternatively in TempDirectory.generateFile you 
could create a File from prefix/n/suffix and call getName to check that 
its matches. If not then throw an exception.


More information about the core-libs-dev mailing list