apache/pulsar · error · IllegalStateException

Cloning a ${class} generated a ${class}, this is a bug, orig

Error message

Cloning a ${class} generated a ${class}, this is a bug, original error is ${error}

What it means

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.

Source

Thrown at pulsar-client-admin-api/src/main/java/org/apache/pulsar/client/admin/PulsarAdminException.java:247

        public GettingAuthenticationDataException(String msg) {
            super(msg);
        }

        @Override
        protected PulsarAdminException clone() {
            return new GettingAuthenticationDataException(getCause());
        }
    }

    /**
     * Clone the exception and grab the current stacktrace.
     * @param e a PulsarAdminException
     * @return a new PulsarAdminException, of the same class.
     */
    public static PulsarAdminException wrap(PulsarAdminException e) {
        PulsarAdminException cloned =  e.clone();
        if (e.getClass() != cloned.getClass()) {
            throw new IllegalStateException("Cloning a " + e.getClass() + " generated a "
                    + cloned.getClass() + ", this is a bug, original error is " + e, e);
        }
        // adding a reference to the original exception.
        cloned.addSuppressed(e);
        return (PulsarAdminException) cloned.fillInStackTrace();
    }
}

View on GitHub (pinned to 820761864e)

Solutions

  1. Report/inspect the original exception (attached as cause and suppressed) — it contains the real admin error.
  2. If using a custom exception subclass, override clone() to return the same concrete class.
  3. Check for mismatched pulsar-client-admin-api versions on the classpath and align them.
  4. As a workaround, catch the original PulsarAdminException directly instead of relying on wrap().

Example fix

// before
class MyAdminException extends PulsarAdminException { } // no clone override
// after
class MyAdminException extends PulsarAdminException {
    @Override
    public PulsarAdminException clone() {
        return new MyAdminException(this); // same concrete class
    }
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
    PulsarAdminException wrapped = PulsarAdminException.wrap(e);
} catch (IllegalStateException bug) {
    PulsarAdminException original = (PulsarAdminException) bug.getCause(); // real error
    handle(original);
}

Prevention

When it happens

Trigger: 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.

Common situations: Custom PulsarAdminException subclasses added in a fork or newer release with a missing/incorrect clone override; mixed client library versions on the classpath.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/babe56c7eae2d024. Report an issue: GitHub.