{"record":{"id":"5423f56d9db87907","repo":"apache/beam","slug":"provided-coders-for-type-arguments-of-s-contain","errorCode":null,"errorMessage":"Provided coders for type arguments of %s contain incompatibilities: Cannot encode elements of type %s with coder %s","messagePattern":"Provided coders for type arguments of (.+?) contain incompatibilities: Cannot encode elements of type (.+?) with coder (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/CoderRegistry.java","lineNumber":446,"sourceCode":"    }\n    ParameterizedType parameterizedType = (ParameterizedType) type;\n    Type[] typeArgs = parameterizedType.getActualTypeArguments();\n    if (knownCoders == null) {\n      knownCoders = new Coder<?>[typeArgs.length];\n    } else if (typeArgs.length != knownCoders.length) {\n      throw new IllegalArgumentException(\n          String.format(\n              \"Class %s has %d parameters, but %d coders are requested.\",\n              baseClass.getCanonicalName(), typeArgs.length, knownCoders.length));\n    }\n\n    SetMultimap<Type, Coder<?>> context = HashMultimap.create();\n    for (int i = 0; i < knownCoders.length; i++) {\n      if (knownCoders[i] != null) {\n        try {\n          verifyCompatible(knownCoders[i], typeArgs[i]);\n        } catch (IncompatibleCoderException exn) {\n          throw new IllegalArgumentException(\n              String.format(\n                  \"Provided coders for type arguments of %s contain incompatibilities:\"\n                      + \" Cannot encode elements of type %s with coder %s\",\n                  baseClass, typeArgs[i], knownCoders[i]),\n              exn);\n        }\n        context.putAll(getTypeToCoderBindings(typeArgs[i], knownCoders[i]));\n      }\n    }\n\n    Coder<?>[] result = new Coder<?>[typeArgs.length];\n    for (int i = 0; i < knownCoders.length; i++) {\n      if (knownCoders[i] != null) {\n        result[i] = knownCoders[i];\n      } else {\n        try {\n          result[i] = getCoderFromTypeDescriptor(TypeDescriptor.of(typeArgs[i]), context);\n        } catch (CannotProvideCoderException exc) {","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/CoderRegistry.java#L428-L464","documentation":"CoderRegistry validated the coders supplied for a class's generic type arguments and found one incompatible: the coder cannot encode a value of the given type. The registry verifies each provided coder against its corresponding type argument via verifyCompatible, and wraps any IncompatibleCoderException into this IllegalArgumentException naming the base class, the offending type, and the coder. This guards against registering a default coder that would fail at encode/decode time.","triggerScenarios":"Calling CoderRegistry.getDefaultCoders (directly or via getCoder) for a parameterized type while passing a context array of known coders where coder[i] does not handle typeArgs[i], e.g. a Coder<Integer> bound to a String type argument.","commonSituations":"Generic pipeline code with TypeDescriptor-supplied coders; refactoring a field's Java type without updating the registered coder; registering a custom coder for a superclass while the actual element type is a different branch of the hierarchy.","solutions":["Check the reported type and coder: ensure the coder's encoded type is assignable from the type argument (Coder.getEncodedTypeDescriptor).","Fix the coder binding so each type argument gets a coder for exactly that type.","Register coders via registerCoderForType(TypeDescriptor, Coder) with matching generic parameters.","If a custom coder's getCoderArguments are wrong, correct them so verifyCompatible recurses correctly."],"exampleFix":"// before\nregistry.getDefaultCoders(TypeDescriptor.of(MyClass.class), new Coder<?>[]{StringUtf8Coder.of()}); // field is Integer\n// after\nregistry.getDefaultCoders(TypeDescriptor.of(MyClass.class), new Coder<?>[]{VarIntCoder.of()});","handlingStrategy":"try-catch","validationCode":"for (int i = 0; i < coders.length; i++) {\n  if (coders[i] != null && !coders[i].getEncodedTypeDescriptor().getRawType()\n      .isAssignableFrom(rawTypeArgs[i])) {\n    throw new IllegalStateException(\"coder \" + i + \" cannot encode \" + rawTypeArgs[i]);\n  }\n}","typeGuard":"static boolean coderMatches(Coder<?> c, Class<?> t) {\n  return c != null && c.getEncodedTypeDescriptor().getRawType().isAssignableFrom(t);\n}","tryCatchPattern":"try {\n  Coder<T> coder = registry.getCoder(typeDescriptor, contextCoders);\n} catch (IllegalArgumentException e) {\n  // log coder/type pair, fall back to registry-inferred coder\n}","preventionTips":["Always build coder arrays in the same order as the class's type parameters.","Prefer registerCoderForType over passing ad-hoc context coders.","Add a unit test asserting getDefaultCoders succeeds for your generic pipeline classes."],"tags":["java","apache-beam","coders","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}