{"record":{"id":"aac1423be290bf75","repo":"apache/beam","slug":"error-instantiating-logical-type-s-with-zero-argument","errorCode":null,"errorMessage":"Error instantiating logical type '%s' with zero-argument constructor.","messagePattern":"Error instantiating logical type '(.+?)' with zero-argument constructor\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaTranslation.java","lineNumber":461,"sourceCode":"                  e);\n            }\n          } else {\n            // Logical type without argument. Construct from constructor without parameter\n            try {\n              return FieldType.logicalType(logicalTypeClass.getConstructor().newInstance());\n            } catch (NoSuchMethodException e) {\n              throw new RuntimeException(\n                  String.format(\n                      \"Standard logical type '%s' does not have a zero-argument constructor.\", urn),\n                  e);\n            } catch (IllegalAccessException e) {\n              throw new RuntimeException(\n                  String.format(\n                      \"Standard logical type '%s' has a zero-argument constructor, but it is not accessible.\",\n                      urn),\n                  e);\n            } catch (ReflectiveOperationException e) {\n              throw new RuntimeException(\n                  String.format(\n                      \"Error instantiating logical type '%s' with zero-argument constructor.\", urn),\n                  e);\n            }\n          }\n        }\n        // Special-case for DATETIME and DECIMAL which are logical types in portable representation,\n        // but not yet in Java. (https://github.com/apache/beam/issues/19817)\n        if (urn.equals(URN_BEAM_LOGICAL_MILLIS_INSTANT)) {\n          return FieldType.DATETIME;\n        } else if (urn.equals(URN_BEAM_LOGICAL_DECIMAL)) {\n          return FieldType.DECIMAL;\n        } else if (urn.startsWith(\"beam:logical_type:\")) {\n          if (!logicalType.getPayload().isEmpty()) {\n            // logical type has a payload, try to recover the instance by deserialization\n            try {\n              return FieldType.logicalType(\n                  (LogicalType)","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaTranslation.java#L443-L479","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npublic class MyLogicalType {\n  MyLogicalType() { loadExternalConfig(); } // throws\n}\n// after\npublic class MyLogicalType {\n  public MyLogicalType() { /* safe, no-throw init */ }\n}","handlingStrategy":"try-catch","validationCode":"try { var inst = logicalTypeClass.getDeclaredConstructor().newInstance(); } catch (ReflectiveOperationException e) { throw new IllegalStateException(\"logical type \" + urn + \" cannot be instantiated: \" + e, e); }","typeGuard":"boolean hasAccessibleNoArgCtor(Class<?> c) { try { return java.lang.reflect.Modifier.isPublic(c.getConstructor().getModifiers()); } catch (NoSuchMethodException e) { return false; } }","tryCatchPattern":"try { schemaTranslationCall(); } catch (RuntimeException e) { if (e.getMessage() != null && e.getMessage().contains(\"zero-argument constructor\")) { /* handle: fix logical type ctor / classpath */ } else { throw e; } }","preventionTips":["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"],"tags":["java","reflection","logical-type","deserialization"],"backgroundTag":"class-not-found","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"}