{"record":{"id":"4cb3d33bd9633cf2","repo":"alibaba/nacos","slug":"not-support-to-cancel-fuzzy-watch","errorCode":null,"errorMessage":"not support to cancel fuzzy watch","messagePattern":"not support to cancel fuzzy watch","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"client/src/main/java/com/alibaba/nacos/client/config/impl/ConfigFuzzyWatchContext.java","lineNumber":515,"sourceCode":"                        FUZZY_WATCH_DIFF_SYNC_NOTIFY,\n                        configFuzzyWatcher);\n                }\n            }\n            \n        }\n    }\n    \n    /**\n     * creat a new future of this context.\n     *\n     * @return\n     */\n    public Future<Set<String>> createNewFuture() {\n        Future<Set<String>> future = new Future<Set<String>>() {\n            \n            @Override\n            public boolean cancel(boolean mayInterruptIfRunning) {\n                throw new UnsupportedOperationException(\"not support to cancel fuzzy watch\");\n            }\n            \n            @Override\n            public boolean isCancelled() {\n                return false;\n            }\n            \n            @Override\n            public boolean isDone() {\n                return ConfigFuzzyWatchContext.this.initializationCompleted.get();\n            }\n            \n            @Override\n            public Set<String> get() throws InterruptedException, ExecutionException {\n                synchronized (ConfigFuzzyWatchContext.this) {\n                    while (!ConfigFuzzyWatchContext.this.initializationCompleted.get()) {\n                        ConfigFuzzyWatchContext.this.wait();\n                    }","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/client/src/main/java/com/alibaba/nacos/client/config/impl/ConfigFuzzyWatchContext.java#L497-L533","documentation":"Thrown as UnsupportedOperationException by the Future returned from ConfigFuzzyWatchContext.createNewFuture().cancel(). Fuzzy watch does not support cancellation — the context tracks initialization completion driven by the server, so a client cannot abort it. Calling cancel() is an API misuse; isCancelled() always returns false.","triggerScenarios":"Taking the Future<Set<String>> from a fuzzy watch context and invoking future.cancel(true/false) on it, e.g. via a generic task runner that cancels futures on timeout.","commonSituations":"Integrating fuzzy watch into a framework (CompletableFuture composition, scheduled executor) that automatically cancels child futures, or explicit cancel-on-timeout logic.","solutions":["Do not call cancel() on the fuzzy-watch future; treat it as non-cancellable.","If using a framework that cancels, wrap the future to no-op cancel().","Rely on the timeout overload of get(timeout, unit) instead of cancel for bounded waits."],"exampleFix":"// before\nFuture<Set<String>> f = context.createNewFuture();\nif (!f.isDone()) f.cancel(true);\n\n// after\nFuture<Set<String>> f = context.createNewFuture();\ntry {\n    Set<String> keys = f.get(5, TimeUnit.SECONDS);\n} catch (TimeoutException te) {\n    // give up the bounded wait; do NOT call f.cancel()","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// never call cancel() on a fuzzy-watch future; it is non-cancellable\nstatic boolean isCancellable(Future<?> f) {\n    return false; // for fuzzy watch contexts\n}","tryCatchPattern":"// do not catch UnsupportedOperationException from cancel — avoid calling cancel\nSet<String> keys;\ntry {\n    keys = future.get(timeout, unit);\n} catch (TimeoutException | InterruptedException e) {\n    // bounded wait expired; do NOT future.cancel()","preventionTips":["Never invoke cancel() on a fuzzy-watch future.","Use get(timeout, unit) for bounded waits instead of cancel.","Wrap the future if a framework insists on cancelling."],"tags":["config","fuzzy-watch","future","client","unsupported"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}