{"record":{"id":"5d0a27b97c3f276b","repo":"apache/beam","slug":"class-s-has-a-defaultcoder-annotation-with-a-null-value","errorCode":null,"errorMessage":"Class %s has a @DefaultCoder annotation with a null value.","messagePattern":"Class (.+?) has a @DefaultCoder annotation with a null value\\.","errorType":"exception","errorClass":"CannotProvideCoderException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/DefaultCoder.java","lineNumber":109,"sourceCode":"        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) {\n          throw new CannotProvideCoderException(\n              String.format(\n                  \"Unable to find 'public static CoderProvider getCoderProvider()' on %s\",\n                  defaultAnnotationValue),\n              e);\n        }\n","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/DefaultCoder.java#L91-L127","documentation":"Thrown by DefaultCoder.coderFor when a @DefaultCoder annotation is present but its value() returns null, i.e. no CoderProvider class was supplied to the annotation. The annotation exists but names no provider, so Beam cannot construct a coder and raises CannotProvideCoderException.","triggerScenarios":"Declaring @DefaultCoder on a class without specifying the value, e.g. @DefaultCoder with no CoderProvider class argument (possible with custom annotation misuse or programmatic construction of the annotation proxy).","commonSituations":"Copy-pasting @DefaultCoder without filling in the coder class; custom annotation implementations where value() is mis-declared with a default of null; annotation processing errors stripping the value.","solutions":["Provide the CoderProvider class in the annotation: @DefaultCoder(FooCoder.FooCoderProvider.class).","Check that the annotation used is actually org.apache.beam.sdk.coders.DefaultCoder, not a same-named custom one with a nullable value().","If a custom annotation wrapper is used, ensure it always sets value() to a non-null CoderProvider class."],"exampleFix":"// before\n@DefaultCoder\n@AutoValue\npublic abstract class Event { ... }\n\n// after\n@DefaultCoder(EventCoder.EventCoderProvider.class)\n@AutoValue\npublic abstract class Event { ... }","handlingStrategy":"validation","validationCode":"DefaultCoder ann = MyType.class.getAnnotation(DefaultCoder.class);\nif (ann == null || ann.value() == null) {\n  throw new IllegalStateException(\"@DefaultCoder must specify a CoderProvider class\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  coder = coderRegistry.getCoder(TypeDescriptor.of(MyType.class));\n} catch (CannotProvideCoderException e) {\n  coder = MyFallbackCoder.of();\n}","preventionTips":["Never write @DefaultCoder without its value argument.","Verify with a unit test that every pipeline element type resolves a coder."],"tags":["beam","java","coders","annotation"],"backgroundTag":"missing-required-argument","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"}