From 8fc650a81fc9195f17d5c0f15c5856394164dcbc Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 21 Jun 2026 08:16:26 +0000 Subject: [PATCH] fix: #101 guard atomic shutdown hook with locked flag Skip the unlock call when the lock was never acquired, so a JVM exit during the acquisition wait or after a thrown lock() or sleep() no longer releases another holder's lock through the empty default label. --- src/main/java/co/stateful/Atomic.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/co/stateful/Atomic.java b/src/main/java/co/stateful/Atomic.java index c66e77e..f48b967 100644 --- a/src/main/java/co/stateful/Atomic.java +++ b/src/main/java/co/stateful/Atomic.java @@ -122,6 +122,9 @@ public Atomic(final Callable clbl, final Lock lck, final String lbl, public T call() throws Exception { final Thread hook = new Thread( () -> { + if (!this.locked.get()) { + return; + } try { this.lock.unlock(this.label); } catch (final IOException ex) {