{"record":{"id":"c050f781ac73b727","repo":"ReactiveX/RxJava","slug":"the-class-does-not-support-isdisposed","errorCode":null,"errorMessage":"The class {} does not support isDisposed","messagePattern":"The class (.+?) does not support isDisposed","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/reactivex/rxjava4/internal/disposables/DisposableOnly.java","lineNumber":28,"sourceCode":" * distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See\n * the License for the specific language governing permissions and limitations under the License.\n */\n\npackage io.reactivex.rxjava4.internal.disposables;\n\nimport io.reactivex.rxjava4.disposables.Disposable;\n\n/**\n * An extension to {@link Disposable} that allows not\n * implementing the {@link Disposable#isDisposed()} as it\n * is practically never needed or cannot be observed anyways.\n * @since 4.0.0\n */\npublic interface DisposableOnly extends Disposable {\n\n    @Override\n    default boolean isDisposed() {\n        throw new UnsupportedOperationException(\"The class \" + this.getClass() + \" does not support isDisposed\");\n    }\n}\n","sourceCodeStart":10,"sourceCodeEnd":31,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/internal/disposables/DisposableOnly.java#L10-L31","documentation":"Thrown by the default isDisposed() implementation inherited via the DisposableOnly interface. DisposableOnly extends Disposable but explicitly opts out of implementing isDisposed(), because for many disposable resources the disposed state is either never observable or never queried in practice. Any code that calls isDisposed() on an instance typed only as DisposableOnly/Disposable will hit this UnsupportedOperationException at runtime — the compiler will not warn because the method exists on the interface.","triggerScenarios":"Calling isDisposed() on an object whose static or declared type is DisposableOnly (or a class implementing it without overriding isDisposed). Common when a resource is stored in a Disposable-typed field or passed to a helper that defensively calls isDisposed().","commonSituations":"Generic resource-tracking utilities that call isDisposed() on every Disposable; testing helpers that assert disposed state; migrating from RxJava 2/3 where isDisposed() was always implemented; using CompositeDisposable-like bookkeeping that probes state.","solutions":["Do not call isDisposed() on DisposableOnly instances; track disposal yourself (e.g. via a boolean flag set in dispose()).","Narrow the type so callers cannot reach isDisposed(), or override isDisposed() in the implementing class if the state is actually observable.","In shared helpers, guard with an instanceof/type check (see defense) before invoking isDisposed().","If you genuinely need disposed-state observation, use a full Disposable implementation (e.g. via a ref-counted or AtomicBoolean-based disposable) instead of DisposableOnly."],"exampleFix":"// before\nDisposableOnly d = createResource();\nif (d.isDisposed()) { ... } // throws UnsupportedOperationException\n\n// after\nDisposableOnly d = createResource();\n// track disposal yourself; never call isDisposed() on DisposableOnly","handlingStrategy":"type-guard","validationCode":"boolean safeIsDisposed(Disposable d) {\n    if (d instanceof DisposableOnly && !overridesIsDisposed(d)) {\n        return false; // state not observable; assume not disposed or track externally\n    }\n    return d.isDisposed();\n}","typeGuard":"boolean isFullyObservable(Disposable d) {\n    // DisposableOnly opts out of isDisposed by default; treat such instances as non-queryable.\n    return !(d instanceof DisposableOnly);\n}","tryCatchPattern":null,"preventionTips":["Never call isDisposed() on DisposableOnly-typed references; track a local disposed flag instead.","In shared resource utilities, type-check for DisposableOnly before probing isDisposed().","If you need observable disposal, implement a full Disposable rather than DisposableOnly."],"tags":["unsupported-operation","disposable","disposal","rxjava","type-design"],"backgroundTag":null,"analyzedSha":"a8ab5356143f37a8f1dd6d76c79191bec5fa343b","analyzedAt":"2026-08-13T23:25:30.069Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}