apache/beam · error · RuntimeException
Error instantiating logical type '%s' with zero-argument con
Error message
Error instantiating logical type '%s' with zero-argument constructor.
What it means
SchemaTranslation instantiates a custom LogicalType from its URN by reflectively calling its zero-argument constructor. This error wraps any ReflectiveOperationException (InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException) thrown during that reflective instantiation. It means the logical type class exists and declares a zero-arg constructor but the reflective call failed.
Source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaTranslation.java:461
e);
}
} else {
// Logical type without argument. Construct from constructor without parameter
try {
return FieldType.logicalType(logicalTypeClass.getConstructor().newInstance());
} catch (NoSuchMethodException e) {
throw new RuntimeException(
String.format(
"Standard logical type '%s' does not have a zero-argument constructor.", urn),
e);
} catch (IllegalAccessException e) {
throw new RuntimeException(
String.format(
"Standard logical type '%s' has a zero-argument constructor, but it is not accessible.",
urn),
e);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(
String.format(
"Error instantiating logical type '%s' with zero-argument constructor.", urn),
e);
}
}
}
// Special-case for DATETIME and DECIMAL which are logical types in portable representation,
// but not yet in Java. (https://github.com/apache/beam/issues/19817)
if (urn.equals(URN_BEAM_LOGICAL_MILLIS_INSTANT)) {
return FieldType.DATETIME;
} else if (urn.equals(URN_BEAM_LOGICAL_DECIMAL)) {
return FieldType.DECIMAL;
} else if (urn.startsWith("beam:logical_type:")) {
if (!logicalType.getPayload().isEmpty()) {
// logical type has a payload, try to recover the instance by deserialization
try {
return FieldType.logicalType(
(LogicalType)View on GitHub (pinned to 12126d8942)
Solutions
- Make the logical type's zero-argument constructor public, side-effect-free, and not throwing; verify its static initializers succeed.
- Open the module/package for reflective access (module-info: opens, or --add-opens) if JPMS blocks it.
- Ensure the same jar/version of the logical type class is on the runtime classpath as at serialization time.
- Wrap constructor work in try/catch or defer it so the no-arg constructor never throws.
- If the constructor genuinely needs arguments, switch the logical type to use a TypesMethodName/argumentType-based construction instead of the zero-arg path.
Example fix
// before
public class MyLogicalType {
MyLogicalType() { loadExternalConfig(); } // throws
}
// after
public class MyLogicalType {
public MyLogicalType() { /* safe, no-throw init */ }
} Defensive patterns
Strategy: try-catch
Validate before calling
try { var inst = logicalTypeClass.getDeclaredConstructor().newInstance(); } catch (ReflectiveOperationException e) { throw new IllegalStateException("logical type " + urn + " cannot be instantiated: " + e, e); } Type guard
boolean hasAccessibleNoArgCtor(Class<?> c) { try { return java.lang.reflect.Modifier.isPublic(c.getConstructor().getModifiers()); } catch (NoSuchMethodException e) { return false; } } Try / catch
try { schemaTranslationCall(); } catch (RuntimeException e) { if (e.getMessage() != null && e.getMessage().contains("zero-argument constructor")) { /* handle: fix logical type ctor / classpath */ } else { throw e; } } Prevention
- Keep logical type no-arg constructors public, empty, and non-throwing
- Avoid side effects or external resource access in constructors
- Add --add-opens / module opens when using JPMS
- Pin identical Beam and logical-type jar versions across write/read sides
When it happens
Trigger: fieldTypeFromProtoWithoutNullable decodes a FieldType whose type_info carries a LOGICAL_TYPE with an URN; SchemaTranslation.java:461 throws when Class.newInstance()/getConstructor().newInstance() on that logical type class fails — e.g. the constructor throws, is inaccessible, or a no-arg constructor lookup fails after the earlier access check path.
Common situations: Custom logical types whose no-arg constructor throws during class init or construction; constructors with side effects that fail (missing config, external resources); classes from another classloader/module not accessible reflectively; Java module system (JPMS) blocking reflective access after migration; class changed between serialization and deserialization versions.
Related errors
- Standard logical type '%s' does not have a static of('%s') m
- Error instantiating logical type '%s' with of('%s') method.
- Unsupported underlying type for parsing logical type via cod
- error when invoking Coder factory method
- cannot register Coder : does not have an accessible method n
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/aac1423be290bf75.
Report an issue: GitHub.