{"record":{"id":"914d130f05fd84bf","repo":"apache/pulsar","slug":"user-class-must-be-concrete-914d13","errorCode":null,"errorMessage":"User class must be concrete","messagePattern":"User class must be concrete","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/runtime-all/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceMain.java","lineNumber":146,"sourceCode":"        }\n    }\n\n    public static Object createInstance(String userClassName,\n                                        ClassLoader classLoader) {\n        Class<?> theCls;\n        try {\n            theCls = Class.forName(userClassName, true, classLoader);\n        } catch (ClassNotFoundException | NoClassDefFoundError cnfe) {\n            throw new RuntimeException(\"Class \" + userClassName + \" must be in class path\", cnfe);\n        }\n        Object result;\n        try {\n            Constructor<?> meth = theCls.getDeclaredConstructor();\n            meth.setAccessible(true);\n\n            result = meth.newInstance();\n        } catch (InstantiationException ie) {\n            throw new RuntimeException(\"User class must be concrete\", ie);\n        } catch (NoSuchMethodException e) {\n            throw new RuntimeException(\"Class \" + userClassName + \" doesn't have such method\", e);\n        } catch (IllegalAccessException e) {\n            throw new RuntimeException(\"Class \" + userClassName + \" must have a no-arg constructor\", e);\n        } catch (InvocationTargetException e) {\n            throw new RuntimeException(\"Class \" + userClassName + \" constructor throws exception\", e);\n        }\n        return result;\n    }\n\n    public static ClassLoader loadJar(ClassLoader parent, File[] jars) throws MalformedURLException {\n        URL[] urls = new URL[jars.length];\n        for (int i = 0; i < jars.length; i++) {\n            urls[i] = jars[i].toURI().toURL();\n        }\n        return new URLClassLoader(urls, parent);\n    }\n","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/runtime-all/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceMain.java#L128-L164","documentation":"createInstance() instantiates the user class via its no-arg constructor. InstantiationException is thrown by the JVM when the loaded class is abstract or an interface; Pulsar rethrows it as RuntimeException(\"User class must be concrete\") so the operator knows the submitted class cannot be instantiated.","triggerScenarios":"Configuring a function whose className points to an abstract class, interface, or (in some JVM versions) an abstract base class instead of the concrete Function/WindowFunction implementation.","commonSituations":"Pointing className at a shared abstract base class; refactoring made the function abstract; accidentally submitting an interface name; anonymous/abstract adapter classes.","solutions":["Set className to a concrete public class with a no-arg constructor, not an abstract class or interface.","Make the submitted function class non-abstract and implement Function<T,R> (or the relevant interface).","Test instantiation locally with `new MyFunction()` or a tiny reflection snippet before deploying."],"exampleFix":"// before\npublic abstract class MyFunction implements Function<String, Integer> { ... }\n// after\npublic class MyFunction implements Function<String, Integer> { ... }","handlingStrategy":"validation","validationCode":"Class<?> c = Class.forName(className);\nif (java.lang.reflect.Modifier.isAbstract(c.getModifiers()) || c.isInterface()) {\n  throw new IllegalArgumentException(className + \" is abstract/interface; use a concrete class\");\n}","typeGuard":"boolean isConcreteInstantiable(String fcn) { try { Class<?> c = Class.forName(fcn); return !c.isInterface() && !java.lang.reflect.Modifier.isAbstract(c.getModifiers()); } catch (Throwable t) { return false; } }","tryCatchPattern":"try { Object f = JavaInstanceMain.createInstance(className, cl); } catch (RuntimeException e) { if (\"User class must be concrete\".equals(e.getMessage())) { System.err.println(\"Make \" + className + \" a concrete, non-abstract class\"); } throw e; }","preventionTips":["Never point function className at abstract base classes or interfaces.","Unit-test `new MyFunction()` as part of the function's build.","Keep function implementation and abstract logic in separate classes.","Add a submission-time check that the class is instantiable."],"tags":["reflection","instantiation","function-config","java"],"backgroundTag":"class-not-instantiable","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"}