In both `UnixUserDefinedFileAttributeView.read(...)` as well as `UnixUserDefinedFileAttributeView.write(...)`, NativeBuffers get allocated before the file handle is opened. If opening the file fails for whatever reason, an exception is thrown _before_ entering the try-finally block that would close/release the buffer again:
https://github.com/openjdk/jdk/blob/7e52a6e8b37412b43b0024ca067959100c14f508/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java#L187
https://github.com/openjdk/jdk/blob/7e52a6e8b37412b43b0024ca067959100c14f508/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java#L258
To fix these two edge cases, as well as to avoid future similar problems, we should use try-with-resource for all NativeBuffers within UnixUserDefinedFileAttributeView.
https://github.com/openjdk/jdk/blob/7e52a6e8b37412b43b0024ca067959100c14f508/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java#L187
https://github.com/openjdk/jdk/blob/7e52a6e8b37412b43b0024ca067959100c14f508/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java#L258
To fix these two edge cases, as well as to avoid future similar problems, we should use try-with-resource for all NativeBuffers within UnixUserDefinedFileAttributeView.
- blocks
-
JDK-8264112 (fs) Reorder methods/constructor/fields in UnixUserDefinedFileAttributeView.java
-
- Resolved
-
- relates to
-
JDK-8262958 (fs) UnixUserDefinedFileAttributeView cleanup
-
- Resolved
-