{"record":{"id":"9560409be72e30d4","repo":"apache/pulsar","slug":"user-class-doesn-t-have-such-method-956040","errorCode":null,"errorMessage":"User class doesn't have such method","messagePattern":"User class doesn't have such method","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/windowing/WindowFunctionExecutor.java","lineNumber":150,"sourceCode":"        Class<?> theCls;\n        try {\n            theCls = Class.forName(windowConfig.getTimestampExtractorClassName(),\n                    true, Thread.currentThread().getContextClassLoader());\n        } catch (ClassNotFoundException | NoClassDefFoundError cnfe) {\n            throw new RuntimeException(\n                    String.format(\"Timestamp extractor class %s must be in class path\",\n                            windowConfig.getTimestampExtractorClassName()), cnfe);\n        }\n\n        Object result;\n        try {\n            Constructor<?> constructor = theCls.getDeclaredConstructor();\n            constructor.setAccessible(true);\n            result = constructor.newInstance();\n        } catch (InstantiationException ie) {\n            throw new RuntimeException(\"User class must be concrete\", ie);\n        } catch (NoSuchMethodException e) {\n            throw new RuntimeException(\"User class doesn't have such method\", e);\n        } catch (IllegalAccessException e) {\n            throw new RuntimeException(\"User class must have a no-arg constructor\", e);\n        } catch (InvocationTargetException e) {\n            throw new RuntimeException(\"User class constructor throws exception\", e);\n        }\n        Class<?>[] timestampExtractorTypeArgs = TypeResolver.resolveRawArguments(\n                TimestampExtractor.class, result.getClass());\n        Class<?>[] typeArgs = TypeResolver.resolveRawArguments(Function.class, this.getClass());\n        if (!typeArgs[0].equals(timestampExtractorTypeArgs[0])) {\n            throw new RuntimeException(\n                    \"Inconsistent types found between function input type and timestamp extractor type: \"\n                            + \" function type = \" + typeArgs[0] + \", timestamp extractor type = \"\n                            + timestampExtractorTypeArgs[0]);\n        }\n        return (TimestampExtractor<T>) result;\n    }\n\n    private TriggerPolicy<Record<T>, ?> getTriggerPolicy(WindowConfig windowConfig, WindowManager<Record<T>> manager,","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/windowing/WindowFunctionExecutor.java#L132-L168","documentation":"getTimeStampExtractor obtains the extractor's declared no-arg constructor via theCls.getDeclaredConstructor(). If no such constructor exists, NoSuchMethodException is rethrown as \"User class doesn't have such method\". The timestamp extractor must expose a no-arg constructor for reflective instantiation by the executor.","triggerScenarios":"Configured extractor class only defines parameterized constructors; getDeclaredConstructor() with no argument list fails during getWindowManager initialization.","commonSituations":"Constructor requiring config/dependencies injected; code generated with required args; Lombok/records without an explicit no-arg constructor.","solutions":["Add a public no-arg constructor to the timestamp extractor class","If initialization data is needed, use a settable field or static config lookup instead of constructor args","Rebuild/redeploy and verify the class in the jar actually has the constructor (javap -p)"],"exampleFix":"// before\npublic class MyExtractor implements TimestampExtractor<String> {\n    public MyExtractor(String topic) { ... }\n}\n// after\npublic class MyExtractor implements TimestampExtractor<String> {\n    public MyExtractor() { }\n    public MyExtractor(String topic) { ... }\n    public long extractTimestamp(String record) { ... }\n}","handlingStrategy":"validation","validationCode":"try {\n    Class.forName(className).getDeclaredConstructor();\n} catch (NoSuchMethodException e) {\n    throw new IllegalStateException(\"extractor lacks a no-arg constructor: \" + className);\n}","typeGuard":null,"tryCatchPattern":"try {\n    executor.initialize();\n} catch (RuntimeException e) {\n    if (\"User class doesn't have such method\".equals(e.getMessage())) {\n        throw new IllegalStateException(\"add a public no-arg constructor to the extractor\", e);\n    }\n    throw e;\n}","preventionTips":["Always define an explicit public no-arg constructor in extractors","Use `javap -p MyClass` to confirm the constructor exists in the built jar","Avoid constructors with required parameters"],"tags":["pulsar-functions","windowing","reflection","constructor"],"backgroundTag":"class-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"}