{"record":{"id":"cde90cd25ec40de9","repo":"apache/flink","slug":"the-class-is-not-instantiable","errorCode":null,"errorMessage":"The class '{}' is not instantiable: {}","messagePattern":"The class '(.+?)' is not instantiable: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java","lineNumber":393,"sourceCode":"     */\n    public static boolean isNonStaticInnerClass(Class<?> clazz) {\n        return clazz.getEnclosingClass() != null\n                && (clazz.getDeclaringClass() == null || !Modifier.isStatic(clazz.getModifiers()));\n    }\n\n    /**\n     * Performs a standard check whether the class can be instantiated by {@code\n     * Class#newInstance()}.\n     *\n     * @param clazz The class to check.\n     * @throws RuntimeException Thrown, if the class cannot be instantiated by {@code\n     *     Class#newInstance()}.\n     */\n    public static void checkForInstantiation(Class<?> clazz) {\n        final String errorMessage = checkForInstantiationError(clazz);\n\n        if (errorMessage != null) {\n            throw new RuntimeException(\n                    \"The class '\" + clazz.getName() + \"' is not instantiable: \" + errorMessage);\n        }\n    }\n\n    public static String checkForInstantiationError(Class<?> clazz) {\n        if (!isPublic(clazz)) {\n            return \"The class is not public.\";\n        } else if (clazz.isArray()) {\n            return \"The class is an array. An array cannot be simply instantiated, as with a parameterless constructor.\";\n        } else if (!isProperClass(clazz)) {\n            return \"The class is not a proper class. It is either abstract, an interface, or a primitive type.\";\n        } else if (isNonStaticInnerClass(clazz)) {\n            return \"The class is an inner class, but not statically accessible.\";\n        } else if (!hasPublicNullaryConstructor(clazz)) {\n            return \"The class has no (implicit) public nullary constructor, i.e. a constructor without arguments.\";\n        } else {\n            return null;\n        }","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java#L375-L411","documentation":"checkForInstantiation(clazz) converts the diagnostic from checkForInstantiationError into RuntimeException('The class X is not instantiable: <reason>'). The appended reason enumerates the exact structural defect: not public, an array, not a proper class (abstract/interface/primitive), a non-static inner class, or lacking a public nullary constructor. It is called both directly by API users and by instantiate() after a newInstance failure.","triggerScenarios":"Passing an abstract class, interface, array class, non-static inner class, or a class without a public no-arg constructor anywhere Flink must reflectively create instances — UDFs, type serializers, factories discovered by name.","commonSituations":"Registering an interface or abstract base instead of the concrete implementation; nested builder classes forgetting 'static'; Scala case classes / Java classes with only constructor-arg constructors.","solutions":["Use a concrete top-level (or static nested) class with a public no-argument constructor","If the class needs arguments, register a factory that produces instances and let Flink instantiate the factory instead","Add 'static' to nested classes and a public no-op constructor alongside argumented ones"],"exampleFix":"// before\npublic class Outer {\n    public class InnerUdf implements MapFunction<String,String> { ... } // non-static inner\n}\n// after\npublic class Outer {\n    public static class InnerUdf implements MapFunction<String,String> {\n        public InnerUdf() {}\n    }\n}","handlingStrategy":"validation","validationCode":"String err = InstantiationUtil.checkForInstantiationError(clazz);\nif (err != null) throw new IllegalArgumentException(clazz.getName() + \": \" + err);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Concrete class + static (if nested) + public + public no-arg constructor","Use factories for classes that genuinely need constructor arguments"],"tags":["reflection","instantiation","validation"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}