changeset 16469:203402b79715

8152272: Unable to create temporary file using createTempFile method if System.getProperty(file.separator) is used Summary: Normalize the name component of the temporary file path Reviewed-by: rriggs
author bpb
date Fri, 13 Jan 2017 13:31:16 -0800
parents 0e0e0fbc5bf3
children 4208e7466342
files src/java.base/share/classes/java/io/File.java test/java/io/File/createTempFile/Patterns.java
diffstat 2 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/io/File.java	Fri Jan 13 12:35:53 2017 -0800
+++ b/src/java.base/share/classes/java/io/File.java	Fri Jan 13 13:31:16 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1962,6 +1962,9 @@
                 name = sb.toString();
             }
 
+            // Normalize the path component
+            name = fs.normalize(name);
+
             File f = new File(dir, name);
             if (!name.equals(f.getName()) || f.isInvalid()) {
                 if (System.getSecurityManager() != null)
--- a/test/java/io/File/createTempFile/Patterns.java	Fri Jan 13 12:35:53 2017 -0800
+++ b/test/java/io/File/createTempFile/Patterns.java	Fri Jan 13 13:31:16 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,7 +22,7 @@
  */
 
 /* @test
-   @bug 4152178
+   @bug 4152178 8152272
    @summary Check various temp-file prefix/suffix cases */
 
 import java.io.File;
@@ -66,6 +66,7 @@
         cky("xxx", "");
         cky("xxx", "y");
         cky("xxx", ".y");
+        cky("xyz", "Directory" + System.getProperty("file.separator"));
     }
 
 }