{"record":{"id":"a94c87ef75c95cee","repo":"alibaba/nacos","slug":"condition-not-supported-in-nacos-distributed-lock","errorCode":null,"errorMessage":"Condition not supported in Nacos distributed lock","messagePattern":"Condition not supported in Nacos distributed lock","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/com/alibaba/nacos/client/lock/NacosLock.java","lineNumber":338,"sourceCode":"                // to prevent the lock from becoming permanently unusable.\n                localReentrantCount.set(0);\n                watchdog.unregister(key);\n                localReentrantCount.remove();\n                removed = true;\n                LOGGER.error(\"Failed to unlock, key={}\", key, e);\n                throw new IllegalStateException(\"Failed to unlock: \" + key, e);\n            }\n        } finally {\n            inUnlock.remove();\n            if (!removed && localReentrantCount.get() <= 0) {\n                localReentrantCount.remove();\n            }\n        }\n    }\n    \n    @Override\n    public Condition newCondition() {\n        throw new UnsupportedOperationException(\n            \"Condition not supported in Nacos distributed lock\");\n    }\n    \n    public String getKey() {\n        return key;\n    }\n    \n    public String getLockType() {\n        return lockType;\n    }\n}\n","sourceCodeStart":320,"sourceCodeEnd":350,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/client/src/main/java/com/alibaba/nacos/client/lock/NacosLock.java#L320-L350","documentation":"Thrown unconditionally by NacosLock.newCondition() because Nacos distributed locks cannot back a java.util.concurrent.locks.Condition across multiple processes. The class Javadoc documents this as a hard limitation: Condition is not supported in a distributed lock. Any code path that reaches newCondition() (directly or via frameworks that expect Lock.newCondition()) will hit this UnsupportedOperationException.","triggerScenarios":"Calling nacosLock.newCondition() directly; passing a NacosLock to a library or utility that invokes newCondition() (e.g. some channel/queue implementations); using NacosLock in a JUC abstraction layer that requires Condition support.","commonSituations":"Porting local ReentrantLock code that used Condition/signal/await to a distributed NacosLock; generic concurrency frameworks that call newCondition() as part of setup; IDE-assisted refactors that keep await/signal calls.","solutions":["Do not call newCondition() on a NacosLock; remove all Condition/await/signal usage that targets this lock.","If condition-like coordination is needed across processes, use Nacos config listeners, naming subscription events, or a dedicated coordination primitive instead of Condition.","If using a framework that requires Lock.newCondition(), provide a local in-JVM lock for condition waits and use the NacosLock only for mutual exclusion."],"exampleFix":"// before\nNacosLock lock = lockService.getReentrantLock(key);\nCondition cond = lock.newCondition(); // throws\n\n// after — use a local lock for condition coordination\nReentrantLock localLock = new ReentrantLock();\nCondition cond = localLock.newCondition();\nNacosLock distLock = lockService.getReentrantLock(key); // for cross-process mutex only","handlingStrategy":"validation","validationCode":"// Do not call newCondition(); use a local in-JVM lock for condition waits\nReentrantLock local = new ReentrantLock();\nCondition cond = local.newCondition();","typeGuard":"public static boolean supportsCondition(Lock lock) { return !(lock instanceof NacosLock); }","tryCatchPattern":null,"preventionTips":["Do not pass NacosLock to frameworks that require Condition support.","Keep distributed locks for cross-process mutual exclusion only; do condition waits locally."],"tags":["lock","condition","unsupported-operation","distributed-lock","api-limitation"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}