Skip to content

Commit 1572e77

Browse files
committedJan 17, 2023
8283719: java/util/logging/CheckZombieLockTest.java failing intermittently
Backport-of: 74835f73893976c162ef5a441f0cfec16eb8706f
1 parent 48b8fec commit 1572e77

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed
 

‎test/jdk/java/util/logging/CheckZombieLockTest.java

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -50,6 +50,8 @@
5050
import java.util.logging.FileHandler;
5151
import java.util.logging.Level;
5252
import java.util.logging.LogRecord;
53+
import static java.nio.file.StandardOpenOption.*;
54+
5355
public class CheckZombieLockTest {
5456

5557
private static final String WRITABLE_DIR = "writable-lockfile-dir";
@@ -241,10 +243,9 @@ private static void testFileHandlerReuse(File writableDir) throws IOException {
241243
}
242244

243245
if (supportsLocking) {
244-
FileChannel fc = FileChannel.open(Paths.get(lock.getAbsolutePath()),
245-
StandardOpenOption.CREATE_NEW, StandardOpenOption.APPEND,
246-
StandardOpenOption.WRITE);
247-
try {
246+
handler2 = null;
247+
try (FileChannel fc = FileChannel.open(lock.toPath(), CREATE_NEW, APPEND, WRITE)) {
248+
248249
if (fc.tryLock() != null) {
249250
System.out.println("locked: " + lock);
250251
handler2 = createFileHandler(writableDir);
@@ -261,6 +262,7 @@ private static void testFileHandlerReuse(File writableDir) throws IOException {
261262
throw new RuntimeException("Failed to lock: " + lock);
262263
}
263264
} finally {
265+
if (handler2 != null) handler2.close();
264266
delete(lock);
265267
}
266268
}
@@ -320,17 +322,12 @@ private static File setup() throws RuntimeException {
320322

321323
// try to determine whether file locking is supported
322324
final String uniqueFileName = UUID.randomUUID().toString()+".lck";
323-
try {
324-
FileChannel fc = FileChannel.open(Paths.get(writableDir.getAbsolutePath(),
325-
uniqueFileName),
326-
StandardOpenOption.CREATE_NEW, StandardOpenOption.APPEND,
327-
StandardOpenOption.DELETE_ON_CLOSE);
325+
try (FileChannel fc = FileChannel.open(Paths.get(writableDir.getAbsolutePath(),
326+
uniqueFileName), CREATE_NEW, APPEND, DELETE_ON_CLOSE)) {
328327
try {
329328
fc.tryLock();
330-
} catch(IOException x) {
329+
} catch (IOException x) {
331330
supportsLocking = false;
332-
} finally {
333-
fc.close();
334331
}
335332
} catch (IOException t) {
336333
// should not happen

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Jan 17, 2023

@openjdk-notifier[bot]
Please sign in to comment.