JDK-8273935 : (zipfs) Files.getFileAttributeView() throws UOE instead of returning null when view not supported
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 17,18
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2021-09-17
  • Updated: 2022-04-25
  • Resolved: 2021-09-21
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 15 JDK 17 JDK 18
15.0.8Fixed 17.0.2Fixed 18 b16Fixed
Related Reports
Duplicate :  
Relates :  
Description
When trying to get a FileAttributeView from a zip entry JDK 17+ throws an undeclared UnsupportedOperationException. The javadoc of Files.getFileAttributeView() says:

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Files.html#getFileAttributeView(java.nio.file.Path,java.lang.Class,java.nio.file.LinkOption...)
"""
Returns:
    a file attribute view of the specified type, or null if the attribute view type is not available
"""

Yet, an exception is thrown in some cases. That is a regression to JDK 11. See the attached reproducer.

JDK 11 run:
--------------------------
Debug: Creating test-zip-file.zip...
Debug: reading entry: /noperm_entry
Debug: os.name == Linux
Non-Windows Test PASSED! env=posix view=null, featureVersion: 11
Debug: reading entry: /noperm_entry
Debug: os.name == Linux
Non-Windows Test PASSED! env=empty view=null, featureVersion: 11

JDK 17+ runs:
--------------------------
Debug: Creating test-zip-file.zip...
Debug: reading entry: /noperm_entry
Debug: os.name == Linux
Non-Windows Test PASSED! env=posix view=jdk.nio.zipfs.ZipPosixFileAttributeView@2f2c9b19, featureVersion: 17
Debug: reading entry: /noperm_entry
Debug: Files.getFileAttributeView() threw exception: java.lang.UnsupportedOperationException: view <interface java.nio.file.attribute.PosixFileAttributeView> is not supported
Debug: os.name == Linux
Exception in thread "main" java.lang.RuntimeException: Test failed! view=null
	at TestPosixAttributeView.runTest(TestPosixAttributeView.java:83)
	at TestPosixAttributeView.main(TestPosixAttributeView.java:105)

This was originally reported here, where the issue is that on Windows, where Posix permissions are not supported, suddenly throws an exception when it didn't before JDK-8213031:
https://github.com/adoptium/adoptium-support/issues/363
Comments
A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk15u-dev/pull/199 Date: 2022-04-25 12:38:07 +0000
25-04-2022

Fix request (15u) I'd like to backport it to 15 where this issue exists, too. Applies perfectly barring a comma in copyright. All zipfs tests pass OK.
25-04-2022

verified
08-04-2022

Fix Request (OpenJDK 17u): Please approve backporting this fix to 17u. The problem exists there too and was actually discovered as a change in an 11->17 upgrade attempt. The JDK 18 change applies clean and no regressions observed. Should be low risk (return null instead of throwing an undeclared exception).
29-09-2021

Changeset: 161fdb4a Author: Lance Andersen <lancea@openjdk.org> Date: 2021-09-21 19:23:49 +0000 URL: https://git.openjdk.java.net/jdk/commit/161fdb4afbc6e67cc7580fe753112c4d894a9b6b
21-09-2021

Looks like line 71 which throws UnsupportedOperationException, should just return null as UnixFileSystemProvider does
17-09-2021

[~clanger] Perhaps you want to have a look at this?
17-09-2021