apache/beam · error · RuntimeException
Failed to construct instance from constructor +…
Error message
Failed to construct instance from constructor + factoryClass.getName()
What it means
InstanceBuilder.buildFromConstructor() wraps InvocationTargetException, InstantiationException and IllegalAccessException into RuntimeException 'Failed to construct instance from constructor ' + factoryClass.getName(). The constructor was found but invoking it failed: it threw an exception, the class is abstract/interface, or access was denied.
Solutions
- Inspect the wrapped cause (getCause()) to see the constructor's own exception
- Ensure the configured class is concrete (not abstract or an interface)
- Make the constructor public, or fix argument validation inside the constructor
- Fix the invalid arguments that made the constructor throw
Example fix
// before
new InstanceBuilder().fromClassName("java.util.List").build(); // interface
// after
new InstanceBuilder().fromClassName("java.util.ArrayList").build(); Defensive patterns
Strategy: try-catch
Validate before calling
if (java.lang.reflect.Modifier.isAbstract(factoryClass.getModifiers())) { throw new IllegalStateException("cannot instantiate abstract class " + factoryClass.getName()); } Try / catch
try { instance = builder.build(); } catch (RuntimeException e) { log.error("ctor failed", e.getCause()); throw e; } Prevention
- Configure only concrete, instantiable classes
- Inspect getCause() for the constructor's own exception
- Keep constructors side-effect-light and fail fast
When it happens
Trigger: Constructor body threw an exception (wrapped cause); newInstance called on an abstract class or interface; constructor not accessible due to access control.
Common situations: Abstract base class configured as a concrete factory class; constructor validating arguments and throwing; private constructor invoked reflectively.
Related errors
- Standard logical type
- Subclass of InferableFunction must override 'apply' method…
- Unable to find constructor for + factoryClass.getName()
- Unable to generate a creator for class
- Unable to generate a creator for POJO
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/ea27e196437b7388.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/util/InstanceBuilder.java:263
checkState(
type.isAssignableFrom(factoryClass),
"Instance type %s must be assignable to %s",
factoryClass.getName(),
type.getSimpleName());
if (!constructor.isAccessible()) {
constructor.setAccessible(true);
}
Object[] args = arguments.toArray(new Object[arguments.size()]);
return type.cast(constructor.newInstance(args));
} catch (NoSuchMethodException e) {
throw new RuntimeException("Unable to find constructor for " + factoryClass.getName());
} catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
throw new RuntimeException(
"Failed to construct instance from " + "constructor " + factoryClass.getName(), e);
}
}
}
View on GitHub (pinned to 12126d8942)