{"record":{"id":"dd3af2c2c71da49d","repo":"apache/beam","slug":"unable-to-generate-a-have-for-hasmethod-s","errorCode":null,"errorMessage":"Unable to generate a have for hasMethod '%s'","messagePattern":"Unable to generate a have for hasMethod '(.+?)'","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/JavaBeanUtils.java","lineNumber":304,"sourceCode":"      Class<ObjectT> clazz, Method hasMethod) {\n    DynamicType.Builder<FieldValueHaver<ObjectT>> builder =\n        ByteBuddyUtils.subclassHaverInterface(BYTE_BUDDY, clazz);\n    builder = implementHaverMethods(builder, hasMethod);\n    try {\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        | InvocationTargetException\n        | NoSuchMethodException e) {\n      throw new RuntimeException(\"Unable to generate a have for hasMethod '\" + hasMethod + \"'\", e);\n    }\n  }\n\n  private static <ObjectT> DynamicType.Builder<FieldValueHaver<ObjectT>> implementHaverMethods(\n      DynamicType.Builder<FieldValueHaver<ObjectT>> builder, Method hasMethod) {\n    return builder\n        .method(ElementMatchers.named(\"name\"))\n        .intercept(FixedValue.reference(hasMethod.getName()))\n        .method(ElementMatchers.named(\"has\"))\n        .intercept(new InvokeHaverInstruction(hasMethod));\n  }\n\n  // The list of constructors for a class is cached, so we only create the classes the first time\n  // getConstructor is called.\n  public static final Map<TypeDescriptorWithSchema<?>, SchemaUserTypeCreator> CACHED_CREATORS =\n      Maps.newConcurrentMap();\n\n  public static SchemaUserTypeCreator getConstructorCreator(","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/JavaBeanUtils.java#L286-L322","documentation":"JavaBeanUtils.createHaver generates a dynamic FieldValueHaver for a boolean 'has' method of a Java bean. If instantiating the generated class via its reflective no-arg constructor throws InstantiationException, IllegalAccessException, InvocationTargetException, or NoSuchMethodException, this RuntimeException is thrown with the offending hasMethod name.","triggerScenarios":"Calling JavaBeanUtils.getHavers/createHaver for a bean whose has-method's declaring class cannot be reflectively instantiated — e.g. the bean class is abstract, has no accessible no-arg constructor, or the generated proxy cannot be constructed in the current classloader.","commonSituations":"Schema-registered JavaBeans that are nested non-static inner classes (implicit constructor params), beans with package-private visibility, or has-methods on abstract base classes.","solutions":["Make the bean a concrete public class (static nested class if nested) with a public no-arg constructor","Confirm the has-method is on a concrete class, not an interface or abstract class","Inspect the suppressed/cause exception for the precise reflective failure","Simplify to a top-level public class if classloader visibility is the blocker"],"exampleFix":"// before\npublic class Outer {\n  class Inner { public boolean hasValue() { return true; } }\n}\n// after\npublic class Outer {\n  public static class Inner { public boolean hasValue() { return true; } }\n}","handlingStrategy":"validation","validationCode":"static void checkBeanHaver(Class<?> c) {\n  if (c.isInterface() || java.lang.reflect.Modifier.isAbstract(c.getModifiers()))\n    throw new IllegalArgumentException(c + \" must be a concrete class\");\n  try { c.getDeclaredConstructor(); }\n  catch (NoSuchMethodException e) { throw new IllegalArgumentException(c + \" lacks a no-arg constructor\", e); }\n}","typeGuard":"static boolean isConcretePublic(Class<?> c) {\n  return !c.isInterface() && java.lang.reflect.Modifier.isPublic(c.getModifiers())\n      && !java.lang.reflect.Modifier.isAbstract(c.getModifiers());\n}","tryCatchPattern":"try {\n  havers = JavaBeanUtils.getHavers(MyBean.class, schema, options);\n} catch (RuntimeException e) {\n  throw new IllegalStateException(\"Haver generation failed for hasMethod '\" + e.getMessage() + \"'\", e);\n}","preventionTips":["Avoid has-methods on abstract or interface types used as Beam schemas","Keep beans top-level public classes (or public static nested)","Verify reflective instantiation in CI for every schema type"],"tags":["java","reflection","schemas","code-generation"],"backgroundTag":"internal-invariant-violation","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"}