{"record":{"id":"5a215a29adf1c78b","repo":"apache/beam","slug":"unable-to-generate-a-creator-for-pojo-s-with-inferred-schema","errorCode":null,"errorMessage":"Unable to generate a creator for POJO '%s' with inferred schema: %s%nNote POJOs must have a zero-argument constructor, or a constructor annotated with @SchemaCreate.","messagePattern":"Unable to generate a creator for POJO '(.+?)' with inferred schema: (.+?)%nNote POJOs must have a zero-argument constructor, or a constructor annotated with @SchemaCreate\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/POJOUtils.java","lineNumber":177,"sourceCode":"              .subclass(SchemaUserTypeCreator.class)\n              .method(ElementMatchers.named(\"create\"))\n              .intercept(new SetFieldCreateInstruction(types, clazz, typeConversionsFactory));\n\n      return builder\n          .visit(new AsmVisitorWrapper.ForDeclaredMethods().writerFlags(ClassWriter.COMPUTE_FRAMES))\n          .make()\n          .load(\n              ReflectHelpers.findClassLoader(clazz.getClassLoader()),\n              getClassLoadingStrategy(clazz))\n          .getLoaded()\n          .getDeclaredConstructor()\n          .newInstance();\n    } catch (InstantiationException\n        | IllegalAccessException\n        | IllegalStateException\n        | NoSuchMethodException\n        | InvocationTargetException e) {\n      throw new RuntimeException(\n          String.format(\n              \"Unable to generate a creator for POJO '%s' with inferred schema: %s%nNote POJOs must\"\n                  + \" have a zero-argument constructor, or a constructor annotated with\"\n                  + \" @SchemaCreate.\",\n              clazz, schema));\n    }\n  }\n\n  public static <T> SchemaUserTypeCreator getConstructorCreator(\n      TypeDescriptor<T> typeDescriptor,\n      Constructor<T> constructor,\n      Schema schema,\n      FieldValueTypeSupplier fieldValueTypeSupplier,\n      TypeConversionsFactory typeConversionsFactory) {\n    return CACHED_CREATORS.computeIfAbsent(\n        TypeDescriptorWithSchema.create(typeDescriptor, schema),\n        c -> {\n          List<FieldValueTypeInformation> types =","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/POJOUtils.java#L159-L195","documentation":"createSetFieldCreator instantiates a POJO for schema-based row conversion by invoking a zero-argument constructor (or an @SchemaCreate-annotated constructor/method). If instantiation fails — the class is abstract, has no accessible no-arg constructor, the constructor throws, or a method is missing — it throws this RuntimeException with a hint about the @SchemaCreate annotation. The original reflective exception is swallowed, so only the formatted message is visible.","triggerScenarios":"Calling getSetFieldCreator on a POJO class that lacks a public zero-argument constructor and lacks a constructor/method annotated with @SchemaCreate; or whose no-arg constructor itself throws; or an abstract/interface class.","commonSituations":"POJOs defined with only all-args constructors (Lombok @AllArgsConstructor without @NoArgsConstructor), immutable value classes, inner non-static classes whose constructor requires an enclosing instance, or classes whose constructor validates and throws on default values.","solutions":["Add a public zero-argument constructor to the POJO (e.g. Lombok @NoArgsConstructor).","If zero-arg construction is impossible, annotate a static factory method or suitable constructor with @org.apache.beam.sdk.schemas.SchemaCreate so Beam uses it to build instances.","Make sure the class is public, static (if nested), and concrete (not abstract/interface).","Check whether the no-arg constructor throws on default field values (e.g. Objects.requireNonNull) and relax that validation for schema-created instances."],"exampleFix":"// before\npublic class User {\n  private final String name;\n  public User(String name) { this.name = name; }\n}\n// after\npublic class User {\n  private String name;\n  public User() {} // zero-arg constructor for Beam\n  public User(String name) { this.name = name; }\n}\n// or: @SchemaCreate public static User create(String name) { ... }","handlingStrategy":"validation","validationCode":"Class<?> clazz = MyPojo.class;\nboolean ok = Modifier.isPublic(clazz.getModifiers()) && !Modifier.isAbstract(clazz.getModifiers())\n    && java.util.Arrays.stream(clazz.getConstructors()).anyMatch(c -> c.getParameterCount() == 0)\n    || java.util.Arrays.stream(clazz.getDeclaredMethods())\n        .anyMatch(m -> m.isAnnotationPresent(org.apache.beam.sdk.schemas.SchemaCreate.class));\nif (!ok) throw new IllegalStateException(clazz + \" needs a public no-arg ctor or @SchemaCreate\");","typeGuard":null,"tryCatchPattern":"try {\n  SchemaUserTypeCreator creator = POJOUtils.getSetFieldCreator(clazz, schema);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Unable to generate a creator for POJO\")) {\n    throw new IllegalStateException(\"Fix POJO: add no-arg constructor or @SchemaCreate\", e);\n  } else throw e;\n}","preventionTips":["Give every schema POJO a public zero-argument constructor by convention.","Use Lombok @NoArgsConstructor @AllArgsConstructor together for immutable-style POJOs.","Never let the no-arg constructor throw validation errors; validate in setters or a factory instead."],"tags":["java","beam-schema","pojo","reflection","constructor"],"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-14T11:17:12.474Z"}