{"record":{"id":"df2af14c6d0b0017","repo":"alibaba/nacos","slug":"not-support-to-cancel-fuzzy-watch-df2af1","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/naming/cache/NamingFuzzyWatchContext.java","lineNumber":425,"sourceCode":"            return getFuzzyWatchEventWatcherWrappers();\n        } else {\n            return getFuzzyWatchEventWatcherWrappers().stream()\n                .filter(a -> a.getUuid().equals(uuid))\n                .collect(Collectors.toSet());\n        }\n    }\n    \n    /**\n     * create a new future of this context.\n     *\n     * @return\n     */\n    public Future<ListView<String>> createNewFuture() {\n        Future<ListView<String>> completableFuture = new Future<ListView<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 NamingFuzzyWatchContext.this.initializationCompleted.get();\n            }\n            \n            @Override\n            public ListView<String> get() throws InterruptedException {\n                synchronized (NamingFuzzyWatchContext.this) {\n                    while (!NamingFuzzyWatchContext.this.initializationCompleted.get()) {\n                        NamingFuzzyWatchContext.this.wait();\n                    }","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/client/src/main/java/com/alibaba/nacos/client/naming/cache/NamingFuzzyWatchContext.java#L407-L443","documentation":"Thrown by the anonymous Future.cancel(boolean) returned from NamingFuzzyWatchContext.createNewFuture(). Fuzzy watch is a server-driven push model; the client cannot cancel the underlying server subscription through the Future, so cancel() is intentionally unsupported. isCancelled() always returns false. This is a deliberate API contract, not a bug.","triggerScenarios":"Calling future.cancel(true/false) on the Future obtained from a fuzzy watch context; passing the fuzzy-watch Future to a framework that cancels futures (e.g. timeout/cancellation utilities, CompletableFuture orchestration).","commonSituations":"Generic async utilities that call cancel() on any Future they manage; copying patterns from normal CompletableFuture usage into fuzzy-watch code; cleanup hooks that cancel futures.","solutions":["Do not call cancel() on fuzzy-watch futures; manage the subscription lifecycle via the NamingFuzzyWatchServiceListHolder (register/unregister watcher) instead.","If you need cancellation semantics, wrap the future.get(timeout) call and discard the result on timeout rather than calling cancel().","Guard third-party code that may invoke cancel() by checking the future source before calling it."],"exampleFix":"// before\nFuture<ListView<String>> f = context.createNewFuture();\nf.cancel(true); // throws UnsupportedOperationException\n\n// after — use timeout on get() instead of cancel()\nListView<String> result = f.get(5, TimeUnit.SECONDS);","handlingStrategy":"type-guard","validationCode":"// Never call cancel() on fuzzy-watch futures; use get(timeout) instead\nListView<String> keys = future.get(5, TimeUnit.SECONDS);","typeGuard":"public static boolean isCancellable(Future<?> f) { // fuzzy-watch futures throw on cancel; treat them as non-cancellable return false; }","tryCatchPattern":null,"preventionTips":["Do not pass fuzzy-watch futures to frameworks that call cancel().","Manage the fuzzy-watch subscription via register/unregister watcher, not future.cancel().","Use get(timeout) for time-bounded waits."],"tags":["naming","fuzzy-watch","future","unsupported-operation","api-limitation"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}