{"record":{"id":"70fe95c20c148b92","repo":"aeron-io/aeron","slug":"registration-id-is-not-a-publication-resource-getclass","errorCode":null,"errorMessage":"registration id is not a Publication: ${resource.getClass().getSimpleName()}","messagePattern":"registration id is not a Publication: (.+?)","errorType":"validation","errorClass":"AeronException","httpStatus":null,"severity":"error","filePath":"aeron-client/src/main/java/io/aeron/ClientConductor.java","lineNumber":695,"sourceCode":"        }\n    }\n\n    void removePublication(final long publicationRegistrationId)\n    {\n        clientLock.lock();\n        try\n        {\n            if (NULL_VALUE == publicationRegistrationId || isTerminating || isClosed)\n            {\n                return;\n            }\n\n            ensureNotReentrant();\n\n            final Object resource = resourceByRegIdMap.get(publicationRegistrationId);\n            if (null != resource && !(resource instanceof Publication))\n            {\n                throw new AeronException(\"registration id is not a Publication: \" +\n                    resource.getClass().getSimpleName());\n            }\n\n            final Publication publication = (Publication)resource;\n            boolean revokeOnClose = false;\n            if (null != publication)\n            {\n                resourceByRegIdMap.remove(publicationRegistrationId);\n                publication.internalClose();\n                releaseLogBuffers(\n                    publication.logBuffers(), publication.originalRegistrationId(), EXPLICIT_CLOSE_LINGER_NS);\n                revokeOnClose = publication.revokeOnClose;\n            }\n\n            if (asyncCommandIdSet.remove(publicationRegistrationId) || null != publication)\n            {\n                asyncCommandIdSet.add(\n                    driverProxy.removePublication(publicationRegistrationId, revokeOnClose));","sourceCodeStart":677,"sourceCodeEnd":713,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/ClientConductor.java#L677-L713","documentation":"Thrown by Aeron's ClientConductor.removePublication when the supplied registration id maps to a resource that exists but is not a Publication (e.g. a Subscription or Counter). The conductor tracks all client resources by registration id, and this cast-guard prevents releasing the wrong resource type.","triggerScenarios":"Calling aeronClient.removePublication(registrationId) with an id that was returned from addSubscription, addCounter, or another non-publication registration.","commonSituations":"Mixing up registration ids stored in a map/registry; swapping ids after refactoring; reusing a variable holding a subscription id in a release call.","solutions":["Pass the registration id returned by addPublication/addExclusivePublication only.","Check the resource type at the call site; use removeSubscription or removeCounter for other resources.","Fix id bookkeeping (name variables by resource type) so ids cannot be confused."],"exampleFix":"// before\nlong id = client.addSubscription(channel, streamId).registrationId();\nclient.removePublication(id); // AeronException\n// after\nlong pubId = client.addPublication(channel, streamId).registrationId();\nclient.removePublication(pubId);","handlingStrategy":"try-catch","validationCode":"// track ids with the resource that produced them\nif (!(resource instanceof Publication)) throw new IllegalStateException(\"id is not a publication\");\nclient.removePublication(publication.registrationId());","typeGuard":"boolean isPublicationRegId(long regId) { return conductorResourceFor(regId) instanceof Publication; } // maintain your own registry map","tryCatchPattern":"try { client.removePublication(regId); } catch (AeronException e) { log.warn(\"reg id {} is not a Publication: {}\", regId, e.getMessage()); }","preventionTips":["Store registration ids in typed wrappers per resource kind.","Always take the id from the same object you are releasing.","Avoid reusing generic long variables across add/remove calls."],"tags":["java","aeron","client-conductor","resource-management"],"backgroundTag":"type-mismatch","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}