{"record":{"id":"2f1312fd3d916b5e","repo":"apache/beam","slug":"unable-to-find-factory-method-s-s-s","errorCode":null,"errorMessage":"Unable to find factory method %s#%s(%s)","messagePattern":"Unable to find factory method (.+?)#(.+?)\\((.+?)\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/InstanceBuilder.java","lineNumber":217,"sourceCode":"          factoryClass.getName(),\n          method.getName());\n\n      checkState(\n          type.isAssignableFrom(method.getReturnType()),\n          \"Return type for %s#%s must be assignable to %s\",\n          factoryClass.getName(),\n          method.getName(),\n          type.getSimpleName());\n\n      if (!method.isAccessible()) {\n        method.setAccessible(true);\n      }\n\n      Object[] args = arguments.toArray(new Object[arguments.size()]);\n      return type.cast(method.invoke(null, args));\n\n    } catch (NoSuchMethodException e) {\n      throw new RuntimeException(\n          String.format(\n              \"Unable to find factory method %s#%s(%s)\",\n              factoryClass.getSimpleName(), methodName, Joiner.on(\", \").join(types)));\n    } catch (InvocationTargetException e) {\n      if (e.getTargetException() instanceof RuntimeException) {\n        // If underlying exception is unchecked re-raise it as-is\n        throw (RuntimeException) e.getTargetException();\n      }\n      throw new RuntimeException(\n          String.format(\n              \"Encountered checked exception when constructing an instance from factory method %s#%s(%s)\",\n              factoryClass.getSimpleName(), methodName, Joiner.on(\", \").join(types)),\n          e.getTargetException());\n    } catch (IllegalAccessException e) {\n      throw new RuntimeException(\n          String.format(\n              \"Failed to construct instance from factory method %s#%s(%s) due to access restriction\",\n              factoryClass.getSimpleName(), methodName, Joiner.on(\", \").join(types)),","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/InstanceBuilder.java#L199-L235","documentation":"InstanceBuilder.buildFromMethod() throws RuntimeException 'Unable to find factory method %s#%s(%s)' when reflection cannot find a static factory method on the factory class matching the requested name and argument types. This wraps NoSuchMethodException raised during instance construction.","triggerScenarios":"build() is called after setting a factory class and method, but no static method with that name accepts the assembled argument types (wrong name, wrong arity, wrong parameter types).","commonSituations":"Configured factory method name typo; class version changed the method signature; passing types that don't match (e.g. int vs Integer); method is instance-level instead of static.","solutions":["Verify the factory method name and that it is static on the factory class","Match the supplied argument types/arity exactly to the method signature","Check the dependency version so the expected signature exists","Inspect the formatted message: it lists the method name and argument types searched for"],"exampleFix":"// before: method named 'of(String)' but args supplied as Integer\nbuilder.fromClassName(...).fromFactoryMethod(\"of\", 42).build();\n// after\nbuilder.fromClassName(...).fromFactoryMethod(\"of\", \"42\").build();","handlingStrategy":"validation","validationCode":"for (Method m : factoryClass.getMethods()) {\n  if (java.lang.reflect.Modifier.isStatic(m.getModifiers()) && m.getName().equals(methodName)) { return; }\n}\nthrow new IllegalStateException(\"missing static factory method \" + methodName);","typeGuard":null,"tryCatchPattern":"try { builder.build(); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Unable to find factory method\")) { /* fix method name/types */ } throw e; }","preventionTips":["Confirm the factory method is static, public, and matches arg types exactly","Pin dependency versions to avoid signature drift","Copy the exact method signature from the class's source/javadoc"],"tags":["java","reflection","factory-method","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"}