Further UserDefinedFileAttributeView improvements and fixes

Sebastian Stenzel sebastian.stenzel at gmail.com
Tue Mar 2 15:29:48 UTC 2021


> On 2. Mar 2021, at 16:22, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> 
> On 02/03/2021 15:13, Sebastian Stenzel wrote:
>> - fix leaking NativeBuffer by applying try-with-resource where applicable
>> - fix UnsupportedOperationException if trying to read to a Buffer that doesn't provide a backing array
>> 
> I can create bugs but I think it would be useful to know if this the above are real issues or not. All usages of NativeBuffer should already be using try-finally blocks (try-with-resources will improve this of course), have you found cases here this isn't the case? The read method handle both direct and heap buffers, which cases are you running into where the backing memory is something else?
> 
> -Alan.

So far, I just found one case: https://github.com/openjdk/jdk/blob/0de6abd4b49e7111effbaef99a93317bcd7246f0/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java#L230-L258

Variable `nb` declared in line 230, assigned in 237, leaks in 258.

There may be further cases, but this is speculative. Anyway a try-with-resource refactoring should increase robustness.


More information about the nio-dev mailing list