{"record":{"id":"ab713e71a7c9f6d4","repo":"apache/beam","slug":"unable-to-invoke-public-static-coderprovider","errorCode":null,"errorMessage":"Unable to invoke 'public static CoderProvider getCoderProvider()' on %s","messagePattern":"Unable to invoke '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":138,"sourceCode":"        } 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(\n                  \"Unable to invoke 'public static CoderProvider getCoderProvider()' on %s\",\n                  defaultAnnotationValue),\n              e);\n        }\n        return coderProvider.coderFor(typeDescriptor, componentCoders);\n      }\n    }\n  }\n}\n","sourceCodeStart":120,"sourceCodeEnd":149,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/DefaultCoder.java#L120-L149","documentation":"Thrown by DefaultCoder.coderFor when the reflective invocation of getCoderProvider() on the @DefaultCoder-annotated value fails (IllegalAccessException, IllegalArgumentException, InvocationTargetException, NullPointerException, or ExceptionInInitializerError). The method exists but calling it blows up; Beam wraps this in CannotProvideCoderException with the original as the cause.","triggerScenarios":"getCoderProvider() throwing during its body or static initialization; the method being non-public or instance-level despite the name; the CoderProvider constructor throwing inside the factory; class initialization failure of the coder class.","commonSituations":"Coder's static initializer depends on a missing dependency or bad config; factory code throwing NPE on uninitialized state; security manager or module access blocking reflection; partial upgrades where the provider's dependencies are incompatible.","solutions":["Inspect the cause chain (e.getCause()) to find the real failure inside getCoderProvider() and fix it.","Ensure getCoderProvider() is exactly 'public static CoderProvider getCoderProvider()' on a publicly accessible class.","Remove failing dependencies/static initialization from the coder class; make the provider stateless.","Register the coder programmatically via registerCoderForType to bypass the reflective path entirely."],"exampleFix":"// before\npublic static CoderProvider getCoderProvider() {\n  return new EventCoderProvider(UNINITIALIZED_CONFIG); // NPE\n}\n\n// after\npublic static CoderProvider getCoderProvider() {\n  return new EventCoderProvider();\n}","handlingStrategy":"try-catch","validationCode":"// Fail fast in tests:\nAssert.notNull(MyCoder.getCoderProvider(), \"getCoderProvider() must return a provider\");","typeGuard":null,"tryCatchPattern":"try {\n  coder = coderRegistry.getCoder(TypeDescriptor.of(MyType.class));\n} catch (CannotProvideCoderException e) {\n  LOG.error(\"getCoderProvider() failed; cause:\", e.getCause());\n  throw e;\n}","preventionTips":["Inspect getCause() — the reflective failure always carries the real root cause.","Keep CoderProvider factories stateless and free of static-initializer dependencies.","Unit-test coder resolution for every custom annotated type."],"tags":["beam","java","reflection","coders"],"backgroundTag":"unexpected-api-response-shape","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"}