{"record":{"id":"babe56c7eae2d024","repo":"apache/pulsar","slug":"cloning-a-class-generated-a-class-this-is-a","errorCode":null,"errorMessage":"Cloning a ${class} generated a ${class}, this is a bug, original error is ${error}","messagePattern":"Cloning a (.+?) generated a (.+?), this is a bug, original error is (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"pulsar-client-admin-api/src/main/java/org/apache/pulsar/client/admin/PulsarAdminException.java","lineNumber":247,"sourceCode":"        public GettingAuthenticationDataException(String msg) {\n            super(msg);\n        }\n\n        @Override\n        protected PulsarAdminException clone() {\n            return new GettingAuthenticationDataException(getCause());\n        }\n    }\n\n    /**\n     * Clone the exception and grab the current stacktrace.\n     * @param e a PulsarAdminException\n     * @return a new PulsarAdminException, of the same class.\n     */\n    public static PulsarAdminException wrap(PulsarAdminException e) {\n        PulsarAdminException cloned =  e.clone();\n        if (e.getClass() != cloned.getClass()) {\n            throw new IllegalStateException(\"Cloning a \" + e.getClass() + \" generated a \"\n                    + cloned.getClass() + \", this is a bug, original error is \" + e, e);\n        }\n        // adding a reference to the original exception.\n        cloned.addSuppressed(e);\n        return (PulsarAdminException) cloned.fillInStackTrace();\n    }\n}\n","sourceCodeStart":229,"sourceCodeEnd":255,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-admin-api/src/main/java/org/apache/pulsar/client/admin/PulsarAdminException.java#L229-L255","documentation":"IllegalStateException thrown by PulsarAdminException.wrap when cloning a PulsarAdminException yields an instance of a different class — an internal invariant violation indicating a subclass forgot to override clone() correctly. The original exception is attached both as cause and suppressed for diagnostics.","triggerScenarios":"Code calling PulsarAdminException.wrap(e) where e is a subclass whose clone() (or copy logic) returns a different PulsarAdminException subtype. This is a library bug, not a user error.","commonSituations":"Custom PulsarAdminException subclasses added in a fork or newer release with a missing/incorrect clone override; mixed client library versions on the classpath.","solutions":["Report/inspect the original exception (attached as cause and suppressed) — it contains the real admin error.","If using a custom exception subclass, override clone() to return the same concrete class.","Check for mismatched pulsar-client-admin-api versions on the classpath and align them.","As a workaround, catch the original PulsarAdminException directly instead of relying on wrap()."],"exampleFix":"// before\nclass MyAdminException extends PulsarAdminException { } // no clone override\n// after\nclass MyAdminException extends PulsarAdminException {\n    @Override\n    public PulsarAdminException clone() {\n        return new MyAdminException(this); // same concrete class\n    }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    PulsarAdminException wrapped = PulsarAdminException.wrap(e);\n} catch (IllegalStateException bug) {\n    PulsarAdminException original = (PulsarAdminException) bug.getCause(); // real error\n    handle(original);\n}","preventionTips":["Catch the original PulsarAdminException subtype directly instead of relying on wrap()","If you subclass PulsarAdminException, always override clone() to return the same class","Keep pulsar-client-admin-api versions consistent across modules","Treat this exception as a library bug and report it with the suppressed original"],"tags":["bug","reflection","internal"],"backgroundTag":"clone-type-mismatch","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}