apache/beam · error · IllegalArgumentException
cannot register Coder : method named 'of' with arguments of
Error message
cannot register Coder : method named 'of' with arguments of Coder type is not accessible
What it means
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.
Source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/coders/CoderProviders.java:148
+ numTypeParameters
+ " arguments of Coder type is not static");
}
if (!coderClazz.isAssignableFrom(factoryMethodCandidate.getReturnType())) {
throw new IllegalArgumentException(
"cannot register Coder "
+ coderClazz
+ ": "
+ "method named 'of' with "
+ numTypeParameters
+ " arguments of Coder type does not return a "
+ coderClazz);
}
try {
if (!factoryMethodCandidate.isAccessible()) {
factoryMethodCandidate.setAccessible(true);
}
} catch (SecurityException exn) {
throw new IllegalArgumentException(
"cannot register Coder "
+ coderClazz
+ ": "
+ "method named 'of' with "
+ numTypeParameters
+ " arguments of Coder type is not accessible",
exn);
}
return factoryMethodCandidate;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("rawType", rawType)
.add("factoryMethod", factoryMethod)
.toString();View on GitHub (pinned to 12126d8942)
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
Example fix
// before
static <T> MyCoder<T> of(Coder<T> c) { ... } // package-private
// after
public static <T> MyCoder<T> of(Coder<T> c) { ... } Defensive patterns
Strategy: validation
Validate before calling
static boolean ofIsPublic(Class<?> coderClazz) throws NoSuchMethodException {
Class<?>[] argTypes = new Class<?>[coderClazz.getTypeParameters().length];
java.util.Arrays.fill(argTypes, Coder.class);
return java.lang.reflect.Modifier.isPublic(
coderClazz.getDeclaredMethod("of", argTypes).getModifiers());
} Try / catch
try {
CoderProvider provider = CoderProviders.fromStaticMethods(rawType, coderClazz);
} catch (IllegalArgumentException e) {
if (e.getCause() instanceof SecurityException) {
throw new IllegalStateException(
"Grant ReflectPermission('suppressAccessChecks') or make 'of' public", e);
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.
Related errors
- error when invoking Coder factory method
- cannot register Coder : does not have an accessible method n
- cannot register Coder : method named 'of' with arguments of
- cannot register Coder : method named 'of' with arguments of
- Unable to find UserCodeException.wrap
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/5ca2ba6eade81089.
Report an issue: GitHub.