{"record":{"id":"5ca2ba6eade81089","repo":"apache/beam","slug":"cannot-register-coder-method-named-of-with-arguments-of-5ca2ba","errorCode":null,"errorMessage":"cannot register Coder : method named 'of' with  arguments of Coder type is not accessible","messagePattern":"cannot register Coder : method named 'of' with  arguments of Coder type is not accessible","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/CoderProviders.java","lineNumber":148,"sourceCode":"                + 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 {\n        if (!factoryMethodCandidate.isAccessible()) {\n          factoryMethodCandidate.setAccessible(true);\n        }\n      } catch (SecurityException exn) {\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 accessible\",\n            exn);\n      }\n\n      return factoryMethodCandidate;\n    }\n\n    @Override\n    public String toString() {\n      return MoreObjects.toStringHelper(getClass())\n          .add(\"rawType\", rawType)\n          .add(\"factoryMethod\", factoryMethod)\n          .toString();","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/CoderProviders.java#L130-L166","documentation":"After signature checks, getFactoryMethod calls setAccessible(true) on the `of` method so it can be invoked reflectively even if package-private or in a restricted package. If a SecurityManager (or similar access control) rejects the setAccessible call, a SecurityException is caught and rethrown as this IllegalArgumentException. Registration fails because the provider cannot guarantee it can invoke the factory.","triggerScenarios":"CoderProviders.fromStaticMethods(rawType, coderClazz) where coderClazz's `of` method is non-public (package-private/private) or the class is in another module, and the running JVM has a SecurityManager denying suppressAccessChecks, or strong JPMS encapsulation blocks the access widening.","commonSituations":"Package-private `of` methods registered from another package; running inside a sandboxed environment (app server, old SecurityManager policy) without ReflectPermission(\"suppressAccessChecks\"); Java 9+ module encapsulation scenarios in combination with security policies.","solutions":["Make the `of` method `public` in the Coder class so setAccessible is unnecessary","If a SecurityManager is active, grant ReflectPermission(\"suppressAccessChecks\") to the Beam codebase in the policy file","Avoid cross-module reflection: keep the coder class and its factory in an exported/open module","Fall back to CoderProviders.forCoder(typeDescriptor, coderInstance) with a directly constructed coder"],"exampleFix":"// before\nstatic <T> MyCoder<T> of(Coder<T> c) { ... }  // package-private\n// after\npublic static <T> MyCoder<T> of(Coder<T> c) { ... }","handlingStrategy":"validation","validationCode":"static boolean ofIsPublic(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.isPublic(\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.getCause() instanceof SecurityException) {\n    throw new IllegalStateException(\n        \"Grant ReflectPermission('suppressAccessChecks') or make 'of' public\", e);\n  }\n  throw e;\n}","preventionTips":["Declare of() as public so setAccessible(true) is never required","Check SecurityManager policies in deployment environments before using reflective coder registration","On Java 9+ keep coder classes in open/exported modules if registered reflectively across packages","Prefer CoderProviders.forCoder with directly constructed coder instances in sandboxed environments"],"tags":["java","reflection","security","coders","apache-beam"],"backgroundTag":"permission-denied","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"}