{"record":{"id":"38d4c57ec9675b11","repo":"apache/beam","slug":"unable-to-generate-builder-factory-for-clazz","errorCode":null,"errorMessage":"Unable to generate builder factory for clazz","messagePattern":"Unable to generate builder factory for clazz","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/amazon-web-services2/src/main/java/org/apache/beam/sdk/io/aws2/schemas/AwsSchemaUtils.java","lineNumber":74,"sourceCode":"        pojoType.getDeclaredMethods().filter(named(\"builder\").and(isStatic())).getOnly();\n    Generic providerType =\n        Generic.Builder.parameterizedType(FACTORY_TYPE, pojoType, builderMethod.getReturnType())\n            .build();\n\n    try {\n      return (AwsBuilderFactory<PojoT, BuilderT>)\n          BYTE_BUDDY\n              .with(new ByteBuddyUtils.InjectPackageStrategy(clazz))\n              .subclass(providerType)\n              .method(named(\"get\"))\n              .intercept(MethodCall.invoke(builderMethod))\n              .make()\n              .load(ReflectHelpers.findClassLoader(), getClassLoadingStrategy(clazz))\n              .getLoaded()\n              .getDeclaredConstructor()\n              .newInstance();\n    } catch (ReflectiveOperationException e) {\n      throw new RuntimeException(\"Unable to generate builder factory for \" + clazz, e);\n    }\n  }\n\n  static SdkBuilderSetter setter(String name, BiConsumer<SdkBuilder<?, ?>, Object> setter) {\n    return new ValueSetter(name, setter);\n  }\n\n  static <ObjT extends @NonNull Object, ValT> FieldValueGetter<ObjT, ValT> getter(\n      String name, SerializableFunction<ObjT, ValT> getter) {\n    return new ValueGetter<>(name, getter);\n  }\n\n  interface SdkBuilderSetter extends FieldValueSetter<SdkBuilder<?, ?>, Object> {}\n\n  private static class ValueSetter implements SdkBuilderSetter {\n    private final BiConsumer<SdkBuilder<?, ?>, Object> setter;\n    private final String name;\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/amazon-web-services2/src/main/java/org/apache/beam/sdk/io/aws2/schemas/AwsSchemaUtils.java#L56-L92","documentation":"AwsSchemaUtils.builderFactory generates a runtime builder factory class (via ByteBuddy) for an AWS SDK POJO class; if reflective instantiation fails it wraps the ReflectiveOperationException in a RuntimeException 'Unable to generate builder factory for <clazz>'. Typically indicates the class has no accessible no-arg constructor or bytecode generation was blocked.","triggerScenarios":"Generating a builder factory for an AWS SDK class that lacks a no-arg declared constructor; running under a SecurityManager or JVM/module restrictions that block ByteBuddy's reflective access or defineClass; class not visible to the helper's class loader (e.g. fat-jar shading issues).","commonSituations":"Beam pipelines running in environments with module access restrictions (Java 17+); shaded/relocated AWS SDK classes incompatible with ReflectHelpers.findClassLoader; custom or synthetic SdkPojo implementations.","solutions":["Ensure the AWS SDK POJO class is on the classpath and not double-shaded","Run on a JVM/JDK configuration that allows ByteBuddy class generation (add --add-opens as needed)","Check the wrapped ReflectiveOperationException cause for the real failure","Use a standard AWS SDK v2 generated POJO rather than a custom SdkPojo"],"exampleFix":"// before\n// JVM flags: none, Java 17 with strong encapsulation\n// after\n// add JVM flags:\n// --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED","handlingStrategy":"try-catch","validationCode":"try { clazz.getDeclaredConstructor().newInstance(); } catch (ReflectiveOperationException e) { /* fail fast: builder factory generation will fail */ }","typeGuard":"boolean hasNoArgCtor(Class<?> c) { try { c.getDeclaredConstructor(); return true; } catch (NoSuchMethodException e) { return false; } }","tryCatchPattern":"try { factory = AwsSchemaUtils.builderFactory(MyPojo.class); } catch (RuntimeException e) { LOG.error(\"factory generation failed\", e.getCause()); }","preventionTips":["Use standard AWS SDK v2 generated POJOs (they have builders and no-arg constructors)","Avoid shading/relocating AWS SDK classes used with schema providers","Test pipelines on your target JDK (esp. Java 17+) and add --add-opens flags if needed"],"tags":["java","reflection","schemas"],"backgroundTag":"module-init-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}