{"record":{"id":"fb3d759869a2c2a7","repo":"apache/pulsar","slug":"wraps-reflective-instantiation-failure-for-broker","errorCode":null,"errorMessage":"(wraps reflective instantiation failure for BrokerEntryMetadataInterceptor)","messagePattern":"\\(wraps reflective instantiation failure for BrokerEntryMetadataInterceptor\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/intercept/BrokerEntryMetadataUtils.java","lineNumber":51,"sourceCode":"\n    public static Set<BrokerEntryMetadataInterceptor> loadBrokerEntryMetadataInterceptors(\n            Set<String> interceptorNames, ClassLoader classLoader) {\n        Set<BrokerEntryMetadataInterceptor> interceptors = new HashSet<>();\n        if (interceptorNames != null && interceptorNames.size() > 0) {\n            for (String interceptorName : interceptorNames) {\n                try {\n                    @SuppressWarnings(\"unchecked\") // class is loaded by name and expected to implement the interface\n                    Class<BrokerEntryMetadataInterceptor> clz = (Class<BrokerEntryMetadataInterceptor>) ClassLoaderUtils\n                            .loadClass(interceptorName, classLoader);\n                    try {\n                        interceptors.add(clz.getDeclaredConstructor().newInstance());\n                    } catch (InstantiationException | IllegalAccessException\n                            | InvocationTargetException | NoSuchMethodException e) {\n                        log.error()\n                                .attr(\"interceptorName\", interceptorName)\n                                .exception(e)\n                                .log(\"Create new BrokerEntryMetadataInterceptor instance failed.\");\n                        throw new RuntimeException(e);\n                    }\n                } catch (ClassNotFoundException e) {\n                    log.error()\n                            .attr(\"interceptorName\", interceptorName)\n                            .exception(e)\n                            .log(\"Load BrokerEntryMetadataInterceptor class failed.\");\n                    throw new RuntimeException(e);\n                }\n            }\n        }\n        return interceptors;\n    }\n    public static <T> Set<T> loadInterceptors(\n            Set<String> interceptorNames, ClassLoader classLoader) {\n        Set<T> interceptors = new LinkedHashSet<>();\n        if (interceptorNames != null && interceptorNames.size() > 0) {\n            for (String interceptorName : interceptorNames) {\n                try {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/intercept/BrokerEntryMetadataUtils.java#L33-L69","documentation":"BrokerEntryMetadataUtils.loadBrokerEntryMetadataInterceptors instantiates a named BrokerEntryMetadataInterceptor class reflectively. If instantiation fails (abstract class, no no-arg constructor, inaccessible constructor), the checked reflection exceptions are logged and wrapped in a RuntimeException.","triggerScenarios":"brokerEntryMetadataInterceptors config contains a class name whose declared constructor cannot be invoked: class is abstract, has no public no-arg constructor, or the constructor is not accessible.","commonSituations":"Typos or wrong class configured in broker.conf, custom interceptor class not compiled into the broker, interceptor written with a constructor taking arguments.","solutions":["Ensure the interceptor class has a public no-arg constructor and is concrete","Verify the class name in brokerEntryMetadataInterceptors matches a class present on the broker classpath","Check the broker log line 'Create new BrokerEntryMetadataInterceptor instance failed.' for the underlying cause"],"exampleFix":"// before\nclass MyInterceptor implements BrokerEntryMetadataInterceptor {\n    MyInterceptor(String arg) { ... }\n}\n// after\nclass MyInterceptor implements BrokerEntryMetadataInterceptor {\n    public MyInterceptor() { ... }\n}","handlingStrategy":"validation","validationCode":"Class<?> c = Class.forName(interceptorName);\nif (Modifier.isAbstract(c.getModifiers()) || c.isInterface()) {\n    throw new IllegalArgumentException(\"Interceptor must be a concrete class: \" + interceptorName);\n}\nc.getDeclaredConstructor(); // throws NoSuchMethodException if no no-arg ctor\nif (!Modifier.isPublic(c.getModifiers())) {\n    throw new IllegalArgumentException(\"Interceptor class must be public: \" + interceptorName);\n}","typeGuard":null,"tryCatchPattern":"try {\n    interceptors = BrokerEntryMetadataUtils.loadBrokerEntryMetadataInterceptors(names, conf);\n} catch (RuntimeException e) {\n    throw new IllegalStateException(\"Bad BrokerEntryMetadataInterceptor config: check constructor/class\", e);\n}","preventionTips":["Give every custom interceptor a public no-arg constructor","Smoke-test broker startup with the interceptor config before production","Keep interceptor classes on the broker classpath (not only client jars)"],"tags":["reflection","broker-entry-metadata","configuration","pulsar-common"],"backgroundTag":"reflective-instantiation-failed","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}