{"record":{"id":"2a01e8d081b9d4a7","repo":"apache/beam","slug":"method-s-should-not-have-return-type-staticvalueprovider-use","errorCode":null,"errorMessage":"Method %s should not have return type StaticValueProvider, use ValueProvider instead.","messagePattern":"Method (.+?) should not have return type StaticValueProvider, use ValueProvider instead\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/options/ProxyInvocationHandler.java","lineNumber":636,"sourceCode":"   * \"https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html\">default</a> as per\n   * the Java Language Specification for the expected return type is returned.\n   *\n   * @param proxy The proxy object for which we are attempting to get the default.\n   * @param method The getter method that was invoked.\n   * @return The default value from an {@link Default} annotation if present, otherwise a default\n   *     value as per the Java Language Specification.\n   */\n  @SuppressWarnings({\"unchecked\", \"rawtypes\"})\n  private Object getDefault(PipelineOptions proxy, Method method) {\n    if (method.getReturnType().equals(RuntimeValueProvider.class)) {\n      throw new RuntimeException(\n          String.format(\n              \"Method %s should not have return type \"\n                  + \"RuntimeValueProvider, use ValueProvider instead.\",\n              method.getName()));\n    }\n    if (method.getReturnType().equals(StaticValueProvider.class)) {\n      throw new RuntimeException(\n          String.format(\n              \"Method %s should not have return type \"\n                  + \"StaticValueProvider, use ValueProvider instead.\",\n              method.getName()));\n    }\n    @Nullable Object defaultObject = null;\n    for (Annotation annotation : method.getAnnotations()) {\n      defaultObject = returnDefaultHelper(annotation, proxy, method);\n      if (defaultObject != null) {\n        break;\n      }\n    }\n    if (method.getReturnType().equals(ValueProvider.class)) {\n      String propertyName = computedProperties.gettersToPropertyNames.get(method.getName());\n      return defaultObject == null\n          ? new RuntimeValueProvider(\n              method.getName(),\n              propertyName,","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ProxyInvocationHandler.java#L618-L654","documentation":"Same rule as RuntimeValueProvider: PipelineOptions getters must return the ValueProvider interface. ProxyInvocationHandler.getDefault rejects getters declared with the concrete StaticValueProvider type, because StaticValueProvider is an internal implementation that users should not expose in their options interface.","triggerScenarios":"Declaring a custom PipelineOptions getter with return type `StaticValueProvider<T>` (e.g., `StaticValueProvider<String> getFoo();`); thrown when getDefault computes the default during proxy invocation (called via value()).","commonSituations":"Auto-complete picking StaticValueProvider instead of ValueProvider; copying a DoFn that holds a StaticValueProvider field into the options interface; confusing the provider you construct in code with the type you declare in the interface.","solutions":["Change the getter's return type to ValueProvider<T>.","If the value is truly static, just declare a plain type or @Default-annotated ValueProvider getter.","Keep StaticValueProvider usage confined to pipeline construction code (StaticValueProvider.of(...)), not the options interface."],"exampleFix":"// before\ninterface MyOptions extends PipelineOptions {\n  StaticValueProvider<Integer> getLimit();\n}\n// after\ninterface MyOptions extends PipelineOptions {\n  @Default.Integer(100)\n  ValueProvider<Integer> getLimit();\n}","handlingStrategy":"validation","validationCode":"for (Method m : MyOptions.class.getMethods()) {\n  if (m.getReturnType() == StaticValueProvider.class) {\n    throw new IllegalArgumentException(m.getName() + \" must return ValueProvider\");\n  }\n}","typeGuard":"static boolean declaresStaticProvider(Class<? extends PipelineOptions> opts) {\n  return java.util.Arrays.stream(opts.getMethods())\n      .anyMatch(m -> m.getReturnType() == StaticValueProvider.class);\n}","tryCatchPattern":null,"preventionTips":["Declare ValueProvider<T> in options interfaces.","Construct StaticValueProvider.of(...) only in pipeline code, not interface declarations.","Let @Default annotations supply static defaults."],"tags":["java","apache-beam","pipeline-options","valueprovider","api-misuse"],"backgroundTag":"invalid-argument-value","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"}