apache/flink · error · RuntimeException
The class '{}' is not instantiable: {}
Error message
The class '{}' is not instantiable: {} What it means
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.
Source
Thrown at flink-core/src/main/java/org/apache/flink/util/InstantiationUtil.java:393
*/
public static boolean isNonStaticInnerClass(Class<?> clazz) {
return clazz.getEnclosingClass() != null
&& (clazz.getDeclaringClass() == null || !Modifier.isStatic(clazz.getModifiers()));
}
/**
* Performs a standard check whether the class can be instantiated by {@code
* Class#newInstance()}.
*
* @param clazz The class to check.
* @throws RuntimeException Thrown, if the class cannot be instantiated by {@code
* Class#newInstance()}.
*/
public static void checkForInstantiation(Class<?> clazz) {
final String errorMessage = checkForInstantiationError(clazz);
if (errorMessage != null) {
throw new RuntimeException(
"The class '" + clazz.getName() + "' is not instantiable: " + errorMessage);
}
}
public static String checkForInstantiationError(Class<?> clazz) {
if (!isPublic(clazz)) {
return "The class is not public.";
} else if (clazz.isArray()) {
return "The class is an array. An array cannot be simply instantiated, as with a parameterless constructor.";
} else if (!isProperClass(clazz)) {
return "The class is not a proper class. It is either abstract, an interface, or a primitive type.";
} else if (isNonStaticInnerClass(clazz)) {
return "The class is an inner class, but not statically accessible.";
} else if (!hasPublicNullaryConstructor(clazz)) {
return "The class has no (implicit) public nullary constructor, i.e. a constructor without arguments.";
} else {
return null;
}View on GitHub (pinned to 2f3c205e92)
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
Example fix
// before
public class Outer {
public class InnerUdf implements MapFunction<String,String> { ... } // non-static inner
}
// after
public class Outer {
public static class InnerUdf implements MapFunction<String,String> {
public InnerUdf() {}
}
} Defensive patterns
Strategy: validation
Validate before calling
String err = InstantiationUtil.checkForInstantiationError(clazz); if (err != null) throw new IllegalArgumentException(clazz.getName() + ": " + err);
Prevention
- Concrete class + static (if nested) + public + public no-arg constructor
- Use factories for classes that genuinely need constructor arguments
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot create Hadoop WritableTypeInfo.
- Cannot instantiate tuple.
- Could not instantiate type '{}' due to an unspecified except
- Could not instantiate type '{}' Most likely the constructor
- Could not look up the main(String[]) method from the class %
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/cde90cd25ec40de9.
Report an issue: GitHub.