{"record":{"id":"1fc3a4200c705473","repo":"microg/GmsCore","slug":"addoncanceledlistener-is-not-implemented","errorCode":null,"errorMessage":"addOnCanceledListener is not implemented","messagePattern":"addOnCanceledListener is not implemented","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"play-services-tasks/src/main/java/com/google/android/gms/tasks/Task.java","lineNumber":34,"sourceCode":"\n/**\n * Represents an asynchronous operation.\n */\n@PublicApi\npublic abstract class Task<TResult> {\n\n    public Task() {\n    }\n\n    /**\n     * Adds a listener that is called if the Task is canceled.\n     * <p>\n     * The listener will be called on main application thread. If the Task has already been canceled, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.\n     *\n     * @return this Task\n     */\n    public Task<TResult> addOnCanceledListener(OnCanceledListener listener) {\n        throw new UnsupportedOperationException(\"addOnCanceledListener is not implemented\");\n    }\n\n    /**\n     * Adds a listener that is called if the Task is canceled.\n     * <p>\n     * If the Task has already been canceled, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.\n     *\n     * @param executor the executor to use to call the listener\n     * @return this Task\n     */\n    public Task<TResult> addOnCanceledListener(Executor executor, OnCanceledListener listener) {\n        throw new UnsupportedOperationException(\"addOnCanceledListener is not implemented\");\n    }\n\n    /**\n     * Adds an Activity-scoped listener that is called if the Task is canceled.\n     * <p>\n     * The listener will be called on main application thread. If the Task has already been canceled, a call to the listener will be immediately scheduled. If multiple listeners are added, they will be called in the order in which they were added.","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-tasks/src/main/java/com/google/android/gms/tasks/Task.java#L16-L52","documentation":"Task.addOnCanceledListener(OnCanceledListener) is declared in this library's abstract Task class but not implemented; it unconditionally throws UnsupportedOperationException 'addOnCanceledListener is not implemented'. Subclasses are expected to override it; calling it on the base/default implementation always fails.","triggerScenarios":"Registering a cancel listener via the single-argument overload on any Task instance that inherits the base implementation (e.g. a Task returned by an API that does not override this method).","commonSituations":"Using this library's play-services-tasks port (e.g. microG) and adding cancel listeners as in official Google Play Services code; the port lacks the override in the Task implementation being used.","solutions":["Upgrade to a library version whose concrete Task classes implement addOnCanceledListener","Avoid addOnCanceledListener; use addOnCompleteListener and check task.isCanceled() instead","Wrap in try-catch for UnsupportedOperationException if cancel notification is optional","Use a fully implemented Task subclass (e.g. Task from a real TaskCompletionSource flow)"],"exampleFix":"// before\ntask.addOnCanceledListener(listener); // throws\n// after\ntask.addOnCompleteListener(t -> {\n    if (t.isCanceled()) listener.onCanceled();\n});","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    task.addOnCanceledListener(listener);\n} catch (UnsupportedOperationException e) {\n    task.addOnCompleteListener(t -> { if (t.isCanceled()) listener.onCanceled(); });\n}","preventionTips":["Prefer addOnCompleteListener + isCanceled() checks over addOnCanceledListener in this library","Pin a library version known to implement cancel listeners before adopting the API"],"tags":["unsupported-operation","tasks","listeners"],"backgroundTag":"unsupported-operation","analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}