On Fri, 8 Apr 2022 16:37:07 GMT, Daniel Fuchs <dfu...@openjdk.org> wrote:
> Please find enclosed a patch for > `8283719: java/util/logging/CheckZombieLockTest.java failing intermittently` > > My analysis is that the test fails intermittently because the `FileChannel` > created by the test is garbage collected too early, which releases the > associated lock before the `FileHandler` is created. > I have replaced the `try { } finally { }` with a `try-with-resource( ) { } > finally { }` which will prevent the `FileChannel` from being released before > the end of the block. Additional bonus: this should also help with the code > that tries to cleanup the files at the end. > > Though I haven't been able to reproduce the exact failure yet, I haven't > observed the new version of the test failing either. Marked as reviewed by alanb (Reviewer). test/jdk/java/util/logging/CheckZombieLockTest.java line 247: > 245: try (FileChannel fc = > FileChannel.open(Paths.get(lock.getAbsolutePath()), > 246: StandardOpenOption.CREATE_NEW, > StandardOpenOption.APPEND, > 247: StandardOpenOption.WRITE)) { Changing this to use try-with-resources looks good. In passing I wonder why it calls lock.getAbsolutePath(), it's okay to call open with a relative path. Also, if you change this test to use import static then you could change this line to: `try (FileChannel fc = FileChannel.open(Path.of(lock), CREATE_NEW, APPEND, WRITE))` ------------- PR: https://git.openjdk.java.net/jdk/pull/8168