This is the regression introduced with fix for JDK-8013827. The code now checks if file exists before creating new temp file as oppose to earlier where an attempt was made to create file.
Code snippet:
File f;
try {
do {
f = TempDirectory.generateFile(prefix, suffix, tmpdir);
} while (f.exists());
if (!f.createNewFile())
throw new IOException("Unable to create temporary file");
} catch (SecurityException se) {
The call to f.exists now needs "read" permission to be provided for applications which only need to write temp file.
Error:
java.security.AccessControlException: access denied
Exception stack trace:
java.security.AccessControlException: access denied ("java.io.FilePermission" "/tmp/abcd#4910205138484207578.tmp" "read")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:453)
at java.security.AccessController.checkPermission(AccessController.java:820)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
at java.io.File.exists(File.java:814)
at java.io.File.createTempFile(File.java:2003)