AbstractInterruptibleChannel#close / tracking resource leaks

Robert Muir rcmuir at gmail.com
Wed Sep 9 23:03:45 UTC 2015


In lucene we use the FileSystemProvider api to wrap the actual
filesystem during test execution:

* failing tests on resource leaks
* failing tests if they use too many file handles
* shuffling directory listing order in a predictable way
* acting like windows for file deletions
* adding optional low level logging

We don't have problems but there is one ugly part, and that is
delegation around FileChannel.close (because it is final). Our current
solution is an ugly hack:


AsynchronousFileChannel does not have the issue, because its close()
method isn't final, the problem is limited to just FileChannel.

Is there a better way we can do this, or something that could be
improved here?  This evil technique (not surprisingly) fails with the
jigsaw EA build, but it would be great to still be able to wrap the
filesystem in tests to e.g. detect leaks and so on in the future.


More information about the nio-dev mailing list