Skip to content

Commit 34ba40e

Browse files
committed
Prevent NPE during shutdown when the hook is already released
1 parent 865240c commit 34ba40e

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/main/java/org/xbill/DNS/NioClient.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ private static void close(boolean fromHook) {
101101
}
102102

103103
if (!fromHook) {
104-
try {
105-
Runtime.getRuntime().removeShutdownHook(closeThread);
106-
} catch (Exception ex) {
107-
log.warn("Failed to remove shutdown hook, ignoring and continuing close");
104+
synchronized (NIO_CLIENT_LOCK) {
105+
if (closeThread != null) {
106+
try {
107+
Runtime.getRuntime().removeShutdownHook(closeThread);
108+
} catch (Exception ex) {
109+
log.warn("Failed to remove shutdown hook, ignoring and continuing close", ex);
110+
}
111+
}
108112
}
109113
}
110114

0 commit comments

Comments
 (0)