JDK-8289984 : Files:isDirectory and isRegularFile methods not throwing SecurityException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 20
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-07-08
  • Updated: 2022-07-11
  • Resolved: 2022-07-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 20
20 masterFixed
Related Reports
Relates :  
Description
Couple of JCK tests are failing validating the assertion:
"https://download.java.net/java/early_access/jdk19/docs/api/java.base/java/nio/file/Files.html#isDirectory(java.nio.file.Path,java.nio.file.LinkOption...)"

"Throws:
SecurityException - In the case of the default provider, and a security manager is installed, its checkRead method denies read access to the file."

The tests are failing - 
api/java_nio/file/Files/FilesTests.html[isDirectory_03, isRegularFile_03]

possibly regression caused by - https://bugs.openjdk.org/browse/JDK-8283335  in JDKb20-b05

Attached a standalone code which runs with supplied SecurityManager.

Note - It works fine with JDK20-b04.

JDKb20-b04 - Throws SecurityException As expected and checkRead invoked.
====
/scratch/jdk-cache/20/4/jdk-20/bin/java -Djava.security.manager=MySecurityManager TestFilesSecEx
WARNING: A command line option has enabled the Security Manager
WARNING: The Security Manager is deprecated and will be removed in a future release
 The value is java.system.class.loader
 The value is setContextClassLoader
 The value is modifyThreadGroup
 The value is sun.jnu.encoding
 -- CheckRead is invoked --
 The value is /scratch/kganapur/TestFIles/TestFilesSecEx.class
 -- CheckRead is invoked --
 The value is /scratch/kganapur/TestFIles/TestFilesSecEx.class
 -- CheckRead is invoked --
 The value is /scratch/kganapur/TestFIles/TestFilesSecEx.class
 -- CheckRead is invoked --
 The value is C:\Diffs
Exception in thread "main" java.lang.SecurityException: MyException
        at MySecurityManager.checkPermission(MySecurityManager.java:8)
        at java.base/java.lang.SecurityManager.checkRead(SecurityManager.java:751)
        at MySecurityManager.checkRead(MySecurityManager.java:14)
        at java.base/sun.nio.fs.UnixPath.checkRead(UnixPath.java:780)
        at java.base/sun.nio.fs.UnixFileSystemProvider.isDirectory(UnixFileSystemProvider.java:521)
        at java.base/java.nio.file.Files.isDirectory(Files.java:2316)
        at TestFilesSecEx.test01(TestFilesSecEx.java:12)
        at TestFilesSecEx.main(TestFilesSecEx.java:7)

============
JDKb20-b05 -  Does not Throws SecurityException as checkRead is not invoked.

/scratch/jdk-cache/20/5/jdk-20/bin/java -Djava.security.manager=MySecurityManager TestFilesSecEx
WARNING: A command line option has enabled the Security Manager
WARNING: The Security Manager is deprecated and will be removed in a future release
 The value is java.system.class.loader
 The value is setContextClassLoader
 The value is modifyThreadGroup
 The value is sun.jnu.encoding
 -- CheckRead is invoked --
 The value is /scratch/kganapur/TestFIles/TestFilesSecEx.class
 -- CheckRead is invoked --
 The value is /scratch/kganapur/TestFIles/TestFilesSecEx.class
 -- CheckRead is invoked --
 The value is /scratch/kganapur/TestFIles/TestFilesSecEx.class







Comments
Changeset: 6aaf141f Author: Lance Andersen <lancea@openjdk.org> Date: 2022-07-08 18:56:04 +0000 URL: https://git.openjdk.org/jdk/commit/6aaf141f61416104020107c371592812a4c723d9
08-07-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/9433 Date: 2022-07-08 18:13:56 +0000
08-07-2022

The new UnixFileSystemProvider.readAttribtuesIfExists method is missing file.checkRead().The jtreg tests for checking Files methods with a SM is test/jdk/java/nio/file/Files/CheckPermissions.java. It didn't catch this because it pre-dates the new delegation and provider methods. I've added a preliminary patch that should fix it.
08-07-2022