{"record":{"id":"ea27e196437b7388","repo":"apache/beam","slug":"failed-to-construct-instance-from-constructor-factoryclass","errorCode":null,"errorMessage":"Failed to construct instance from constructor + factoryClass.getName()","messagePattern":"Failed to construct instance from constructor \\+ factoryClass\\.getName\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/InstanceBuilder.java","lineNumber":263,"sourceCode":"\n      checkState(\n          type.isAssignableFrom(factoryClass),\n          \"Instance type %s must be assignable to %s\",\n          factoryClass.getName(),\n          type.getSimpleName());\n\n      if (!constructor.isAccessible()) {\n        constructor.setAccessible(true);\n      }\n\n      Object[] args = arguments.toArray(new Object[arguments.size()]);\n      return type.cast(constructor.newInstance(args));\n\n    } catch (NoSuchMethodException e) {\n      throw new RuntimeException(\"Unable to find constructor for \" + factoryClass.getName());\n\n    } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {\n      throw new RuntimeException(\n          \"Failed to construct instance from \" + \"constructor \" + factoryClass.getName(), e);\n    }\n  }\n}\n","sourceCodeStart":245,"sourceCodeEnd":268,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/InstanceBuilder.java#L245-L268","documentation":"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.","triggerScenarios":"Constructor body threw an exception (wrapped cause); newInstance called on an abstract class or interface; constructor not accessible due to access control.","commonSituations":"Abstract base class configured as a concrete factory class; constructor validating arguments and throwing; private constructor invoked reflectively.","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"],"exampleFix":"// before\nnew InstanceBuilder().fromClassName(\"java.util.List\").build(); // interface\n// after\nnew InstanceBuilder().fromClassName(\"java.util.ArrayList\").build();","handlingStrategy":"try-catch","validationCode":"if (java.lang.reflect.Modifier.isAbstract(factoryClass.getModifiers())) { throw new IllegalStateException(\"cannot instantiate abstract class \" + factoryClass.getName()); }","typeGuard":null,"tryCatchPattern":"try { instance = builder.build(); } catch (RuntimeException e) { log.error(\"ctor failed\", e.getCause()); throw e; }","preventionTips":["Configure only concrete, instantiable classes","Inspect getCause() for the constructor's own exception","Keep constructors side-effect-light and fail fast"],"tags":["java","reflection","constructor","instantiation-failed"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}