{"record":{"id":"b32f99a94aad0576","repo":"apache/beam","slug":"unable-to-find-public-static-coderprovider-getcoderprovider","errorCode":null,"errorMessage":"Unable to find 'public static CoderProvider getCoderProvider()' on %s","messagePattern":"Unable to find 'public static CoderProvider getCoderProvider\\(\\)' on (.+?)","errorType":"exception","errorClass":"CannotProvideCoderException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/DefaultCoder.java","lineNumber":121,"sourceCode":"              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\n        CoderProvider coderProvider;\n        try {\n          coderProvider =\n              Preconditions.checkStateNotNull(\n                  (CoderProvider) coderProviderMethod.invoke(clazz /* ignored */));\n        } catch (IllegalAccessException\n            | IllegalArgumentException\n            | InvocationTargetException\n            | NullPointerException\n            | ExceptionInInitializerError e) {\n          throw new CannotProvideCoderException(\n              String.format(","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/DefaultCoder.java#L103-L139","documentation":"Thrown by DefaultCoder.coderFor when the class named in @DefaultCoder does not expose the required static method 'public static CoderProvider getCoderProvider()'. Beam uses reflection to obtain a CoderProvider from the annotated coder class; if the method is missing (NoSuchMethodException) it wraps the failure in CannotProvideCoderException.","triggerScenarios":"Annotating a class @DefaultCoder(FooCoder.class) where FooCoder defines no public static getCoderProvider() method returning CoderProvider; renaming or removing the method during refactoring.","commonSituations":"Hand-writing a custom coder and copying only the encode/decode methods without the provider factory; upgrading a coder library where the provider method was removed; typo like getCodersProvider().","solutions":["Add the static factory to the coder class: public static CoderProvider getCoderProvider() { return new FooCoderProvider(); }.","Use Beam's ProviderHelpers or an existing pattern (e.g. AvroCoder.getCoderProvider()) as a template.","Verify the method signature exactly matches: public static CoderProvider getCoderProvider(), no arguments.","As an alternative, register the coder via coderRegistry.registerCoderForClass(Foo.class, new FooCoder()) instead of relying on the annotation's reflective lookup."],"exampleFix":"// before\npublic class EventCoder extends CustomCoder<Event> { ... }\n\n// after\npublic class EventCoder extends CustomCoder<Event> {\n  public static CoderProvider getCoderProvider() {\n    return CoderProviders.fromStaticMethod(EventCoder.class, \"getCoderProvider\");\n  }\n}","handlingStrategy":"validation","validationCode":"try {\n  MyCoder.class.getMethod(\"getCoderProvider\");\n} catch (NoSuchMethodException e) {\n  throw new IllegalStateException(\"Coder class must define public static CoderProvider getCoderProvider()\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  coder = registry.getCoder(TypeDescriptor.of(MyType.class));\n} catch (CannotProvideCoderException e) {\n  throw new IllegalStateException(\"Misconfigured @DefaultCoder target: \" + e.getMessage(), e);\n}","preventionTips":["Copy the provider pattern from existing coders like AvroCoder.getCoderProvider().","Add a unit test invoking MyCoder.getCoderProvider() so breakage is caught early.","Keep the exact signature: public static CoderProvider getCoderProvider()."],"tags":["beam","java","reflection","coders"],"backgroundTag":"method-not-implemented","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"}