From 9a5d6fa50ed954fbd331b61b0be17b57c6999439 Mon Sep 17 00:00:00 2001 From: leventov Date: Fri, 5 Aug 2016 23:31:09 +0700 Subject: [PATCH] Address the issue with ChronicleHash accessors throwing AssertionError instead of IllegalStateException after ChronicleHash is closed --- .../chronicle/hash/impl/stage/hash/ThreadLocalState.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/hash/impl/stage/hash/ThreadLocalState.java b/src/main/java/net/openhft/chronicle/hash/impl/stage/hash/ThreadLocalState.java index 8121e8137..cff24a2dd 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/stage/hash/ThreadLocalState.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/stage/hash/ThreadLocalState.java @@ -55,8 +55,8 @@ public abstract class ThreadLocalState { * is a nested context. */ public boolean lockContextLocally() { - // h().isOpen() check guarantees no starvation of a thread calling chMap.close() and trying - // to close this context by closeContext() method below, while the thread owning this + // hash().isOpen() check guarantees no starvation of a thread calling chMap.close() and + // trying to close this context by closeContext() method below, while the thread owning this // context frequently locks and unlocks it (e. g. in a loop). This is also the only check // for chMap openness during the whole context usage lifecycle. if (hash().isOpen() && MEMORY.compareAndSwapInt(this, CONTEXT_LOCK_OFFSET, @@ -65,7 +65,9 @@ public abstract class ThreadLocalState { } else { if (contextLock == CONTEXT_LOCKED_LOCALLY) return false; - if (contextLock == CONTEXT_CLOSED) + // Don't extract this hash().isOpen() and the one above, because they could different + // results (the first (above) could return true, the second (below) - false). + if (!hash().isOpen()) throw new ChronicleHashClosedException(); throw new AssertionError("Unknown context lock state: " + contextLock); }