{"record":{"id":"b85657c01b2c577e","repo":"apache/beam","slug":"class-s-does-not-have-a-defaultcoder-annotation","errorCode":null,"errorMessage":"Class %s does not have a @DefaultCoder annotation.","messagePattern":"Class (.+?) does not have a @DefaultCoder annotation\\.","errorType":"exception","errorClass":"CannotProvideCoderException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/DefaultCoder.java","lineNumber":102,"sourceCode":"       */\n      @SuppressFBWarnings(\"DCN_NULLPOINTER_EXCEPTION\") // TODO(#35312)\n      @Override\n      public <T> Coder<T> coderFor(\n          TypeDescriptor<T> typeDescriptor, List<? extends Coder<?>> componentCoders)\n          throws CannotProvideCoderException {\n\n        Class<?> clazz = typeDescriptor.getRawType();\n        DefaultCoder defaultAnnotation = clazz.getAnnotation(DefaultCoder.class);\n        if (defaultAnnotation == null) {\n          // check if the superclass has DefaultCoder annotation if the class is generated using\n          // AutoValue\n          if (clazz.getName().contains(\"AutoValue_\")) {\n            clazz = clazz.getSuperclass();\n            defaultAnnotation = clazz.getAnnotation(DefaultCoder.class);\n          }\n        }\n        if (defaultAnnotation == null) {\n          throw new CannotProvideCoderException(\n              String.format(\"Class %s does not have a @DefaultCoder annotation.\", clazz.getName()));\n        }\n\n        @SuppressWarnings(\"rawtypes\") // this is deliberate, as the user will pass FooCoder.class\n        Class<? extends Coder> defaultAnnotationValue = defaultAnnotation.value();\n        if (defaultAnnotationValue == null) {\n          throw new CannotProvideCoderException(\n              String.format(\n                  \"Class %s has a @DefaultCoder annotation with a null value.\", clazz.getName()));\n        }\n\n        LOG.debug(\n            \"DefaultCoder annotation found for {} with value {}\", clazz, defaultAnnotationValue);\n\n        Method coderProviderMethod;\n        try {\n          coderProviderMethod = defaultAnnotationValue.getMethod(\"getCoderProvider\");\n        } catch (NoSuchMethodException e) {","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/DefaultCoder.java#L84-L120","documentation":"Thrown by DefaultCoder.coderFor when it cannot find a @DefaultCoder annotation on the class (including its AutoValue superclass after walking up one level). The Beam coder registry needs @DefaultCoder to know which CoderProvider supplies a default coder for the type. Without the annotation, Beam refuses to guess a coder and raises CannotProvideCoderException.","triggerScenarios":"Calling CoderRegistry.getCoder(TypeDescriptor<T>) (or a pipeline needing a coder for T) where T's class has no @DefaultCoder annotation and is not registered otherwise; also when an AutoValue_* class's superclass lacks the annotation.","commonSituations":"Using a custom POJO or AutoValue class as a PCollection element without annotating it @DefaultCoder(FooCoder.class); forgetting that @DefaultCoder must sit on the generated class's superclass for AutoValue types; upgrading Beam and relying on removed implicit coders.","solutions":["Annotate the class with @DefaultCoder(YourCoder.class) (on the AutoValue abstract class for AutoValue types).","Alternatively register a coder explicitly: coderRegistry.registerCoderForType(TypeDescriptor.of(Foo.class), new FooCoderProvider()).","Use a built-in codable type or implement/verify the class works with SerializableCoder via @DefaultCoder(AvronCoder.class) as appropriate.","Verify the annotation is on the right class when using AutoValue (the annotation lives on the abstract @AutoValue class, not the generated AutoValue_ subclass)."],"exampleFix":"// before\n@AutoValue\npublic abstract class Event { ... }\n\n// after\n@DefaultCoder(AvroCoder.class)\n@AutoValue\npublic abstract class Event { ... }","handlingStrategy":"validation","validationCode":"if (MyType.class.getAnnotation(org.apache.beam.sdk.coders.DefaultCoder.class) == null) {\n  throw new IllegalStateException(\"Add @DefaultCoder(CoderProviderClass.class) to \" + MyType.class.getName());\n}","typeGuard":null,"tryCatchPattern":"try {\n  Coder<MyType> c = registry.getCoder(TypeDescriptor.of(MyType.class));\n} catch (CannotProvideCoderException e) {\n  // fall back to explicitly registered coder\n  c = new MyTypeCoder();\n}","preventionTips":["Always annotate custom POJO/AutoValue element types with @DefaultCoder at creation time.","For AutoValue, put the annotation on the abstract class, not the generated one.","Prefer explicit coderRegistry.registerCoderForType in pipeline setup for non-annotated types."],"tags":["beam","java","coders","annotation"],"backgroundTag":"missing-required-annotation","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"}