{"record":{"id":"818dc80c05831871","repo":"apache/beam","slug":"cannot-register-coder-method-named-of-with-arguments-of","errorCode":null,"errorMessage":"cannot register Coder : method named 'of' with  arguments of Coder type is not static","messagePattern":"cannot register Coder : method named 'of' with  arguments of Coder type is not static","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/CoderProviders.java","lineNumber":125,"sourceCode":"      // Find the static factory method of coderClazz named 'of' with\n      // the appropriate number of type parameters.\n      int numTypeParameters = coderClazz.getTypeParameters().length;\n      Class<?>[] factoryMethodArgTypes = new Class<?>[numTypeParameters];\n      Arrays.fill(factoryMethodArgTypes, Coder.class);\n      try {\n        factoryMethodCandidate = coderClazz.getDeclaredMethod(\"of\", factoryMethodArgTypes);\n      } catch (NoSuchMethodException | SecurityException exn) {\n        throw new IllegalArgumentException(\n            \"cannot register Coder \"\n                + coderClazz\n                + \": \"\n                + \"does not have an accessible method named 'of' with \"\n                + numTypeParameters\n                + \" arguments of Coder type\",\n            exn);\n      }\n      if (!Modifier.isStatic(factoryMethodCandidate.getModifiers())) {\n        throw new IllegalArgumentException(\n            \"cannot register Coder \"\n                + coderClazz\n                + \": \"\n                + \"method named 'of' with \"\n                + numTypeParameters\n                + \" arguments of Coder type is not static\");\n      }\n      if (!coderClazz.isAssignableFrom(factoryMethodCandidate.getReturnType())) {\n        throw new IllegalArgumentException(\n            \"cannot register Coder \"\n                + coderClazz\n                + \": \"\n                + \"method named 'of' with \"\n                + numTypeParameters\n                + \" arguments of Coder type does not return a \"\n                + coderClazz);\n      }\n      try {","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/CoderProviders.java#L107-L143","documentation":"After locating a method named `of` with the right signature, getFactoryMethod checks Modifier.isStatic. If the `of` method is an instance method, registration with CoderProviders.fromStaticMethods fails with this IllegalArgumentException, because the provider needs to invoke `of` reflectively without any Coder instance.","triggerScenarios":"Declaring `public MyCoder<T> of(Coder<T> component)` (no static keyword) in a Coder class and then calling CoderProviders.fromStaticMethods(rawType, coderClazz).","commonSituations":"Copying a factory method from another coder and dropping the static modifier; auto-generating factory methods (e.g. Lombok @Builder or IDE generation) that produce instance methods; converting a constructor to a factory without making it static.","solutions":["Add the `static` modifier to the `of` method in the Coder class","Ensure the method also matches the required signature: return type assignable to the Coder class, one Coder parameter per type parameter","Alternatively register via CoderProviders.forCoder(typeDescriptor, coderInstance) with a pre-built coder instance"],"exampleFix":"// before\npublic <T> MyCoder<T> of(Coder<T> componentCoder) { return new MyCoder<>(componentCoder); }\n// after\npublic static <T> MyCoder<T> of(Coder<T> componentCoder) { return new MyCoder<>(componentCoder); }","handlingStrategy":"validation","validationCode":"static boolean isOfStatic(Class<?> coderClazz) throws NoSuchMethodException {\n  Class<?>[] argTypes = new Class<?>[coderClazz.getTypeParameters().length];\n  java.util.Arrays.fill(argTypes, Coder.class);\n  return java.lang.reflect.Modifier.isStatic(\n      coderClazz.getDeclaredMethod(\"of\", argTypes).getModifiers());\n}","typeGuard":null,"tryCatchPattern":"try {\n  CoderProvider provider = CoderProviders.fromStaticMethods(rawType, coderClazz);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"is not static\")) {\n    throw new IllegalStateException(\"Fix: declare 'of' as static in \" + coderClazz, e);\n  }\n  throw e;\n}","preventionTips":["Always mark Coder factory methods static — instance methods cannot serve as reflective factories","When IDE-generating builders/factories, verify the generated method is static","Add a unit test that registers every project Coder via fromStaticMethods to catch this at build time","Prefer static factory conventions consistent across your coder library"],"tags":["java","reflection","coders","apache-beam","registration"],"backgroundTag":"missing-required-argument","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"}