{"record":{"id":"21b3b123a38deaf1","repo":"apache/beam","slug":"unable-to-find-constructor-for-factoryclass-getname","errorCode":null,"errorMessage":"Unable to find constructor for + factoryClass.getName()","messagePattern":"Unable to find constructor for \\+ 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":260,"sourceCode":"\n    try {\n      Constructor<?> constructor = factoryClass.getDeclaredConstructor(types);\n\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":242,"sourceCodeEnd":268,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/InstanceBuilder.java#L242-L268","documentation":"InstanceBuilder.buildFromConstructor() throws RuntimeException 'Unable to find constructor for ' + factoryClass.getName() when reflection cannot locate a constructor matching the assembled argument types (wrapping NoSuchMethodException).","triggerScenarios":"build() is called in constructor mode but no constructor of the factory class accepts the collected argument types — wrong arity, wrong types, or a no-arg constructor expected but only parameterized ones exist.","commonSituations":"Configured class has no matching constructor for the given options; class was refactored/renamed constructor signature between versions; autoboxing/primitive mismatches in the argument list.","solutions":["Verify the class exposes a public constructor matching the supplied argument types","Align the argument list with the constructor signature (types and count)","Check the library version for signature changes","Add a convenience constructor if you own the class"],"exampleFix":"// before: class only has MyThing(String) but built with no args\nnew InstanceBuilder().fromClassName(\"MyThing\").build();\n// after\nnew InstanceBuilder().fromClassName(\"MyThing\").withArg(\"name\").build();","handlingStrategy":"validation","validationCode":"boolean hasCtor = java.util.Arrays.stream(factoryClass.getConstructors())\n  .anyMatch(c -> c.getParameterCount() == args.size());\nif (!hasCtor) { throw new IllegalStateException(\"no public ctor with \" + args.size() + \" args\"); }","typeGuard":null,"tryCatchPattern":"try { instance = builder.build(); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Unable to find constructor\")) { /* align ctor signature */ } throw e; }","preventionTips":["Verify a public constructor matches the supplied argument types","Check for signature changes between library versions","Keep classes to be reflectively constructed with explicit public constructors"],"tags":["java","reflection","constructor","method-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}