{"record":{"id":"04e77709144e870f","repo":"apache/beam","slug":"unexpected-write-method-s","errorCode":null,"errorMessage":"Unexpected write method %s","messagePattern":"Unexpected write method (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIO.java","lineNumber":4422,"sourceCode":"                getKmsKey(),\n                getStorageApiTriggeringFrequency(bqOptions),\n                getBigQueryServices(),\n                getStorageApiNumStreams(bqOptions),\n                method == Method.STORAGE_API_AT_LEAST_ONCE,\n                enableAutoSharding,\n                getAutoSchemaUpdate(),\n                getIgnoreUnknownValues(),\n                getPropagateSuccessfulStorageApiWrites(),\n                getPropagateSuccessfulStorageApiWritesPredicate(),\n                getRowMutationInformationFn() != null,\n                getDefaultMissingValueInterpretation(),\n                getBigLakeConfiguration(),\n                getBadRecordRouter(),\n                getBadRecordErrorHandler(),\n                useSchemaUpdate);\n        return input.apply(\"StorageApiLoads\", storageApiLoads);\n      } else {\n        throw new RuntimeException(\"Unexpected write method \" + method);\n      }\n    }\n\n    private boolean hasJsonTypeInSchema(JsonElement schema) {\n      JsonElement fields = schema.getAsJsonObject().get(\"fields\");\n      if (!fields.isJsonArray() || fields.getAsJsonArray().isEmpty()) {\n        return false;\n      }\n\n      JsonArray fieldArray = fields.getAsJsonArray();\n\n      for (int i = 0; i < fieldArray.size(); i++) {\n        JsonObject field = fieldArray.get(i).getAsJsonObject();\n        if (field.get(\"type\").getAsString().equals(\"JSON\")) {\n          return true;\n        }\n\n        if (field.get(\"type\").getAsString().equals(\"STRUCT\")) {","sourceCodeStart":4404,"sourceCodeEnd":4440,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIO.java#L4404-L4440","documentation":"During expansion of BigQueryIO.Write, the pipeline selects an execution method (e.g. FILE_LOADS, STREAMING_INSERTS, STORAGE_API_WRAPPER, STORAGE_LOADS). If the configured Write.Method falls through all known branches, expansion fails with RuntimeException(\"Unexpected write method ...\"). This is an internal invariant check: the method value set on the transform is not one the expansion code knows how to build.","triggerScenarios":"Setting .withMethod(...) to an unrecognized/null method value, or a method combination where earlier guard branches (e.g. getStorageApiTriggeredFileLoads / BigLake configuration) routed the transform into an else-branch whose method field holds a value the expansion cannot dispatch.","commonSituations":"Custom/legacy method constants copied from older Beam versions; programmatically-built transforms whose method field was mutated to an unexpected value; interop/portability paths that deserialize a Write transform with a method name the current SDK does not support.","solutions":["Set an explicit supported method: .withMethod(BigQueryIO.Write.Method.FILE_LOADS), STREAMING_INSERTS, or STORAGE_API_WRAPPER/STORAGE_LOADS as appropriate.","Print/log the method value on the transform (Write#getMethod) to see what actually got set before expansion.","Remove custom method constants and use only BigQueryIO.Write.Method enum values from your Beam version.","If using a cross-language/portable pipeline, ensure the submitting SDK version supports the method; upgrade Beam."],"exampleFix":"// before\nWrite<T> w = io.withMethod(\"storage_write_api\");\n// after\nWrite<T> w = io.withMethod(BigQueryIO.Write.Method.STORAGE_API_WRAPPER);","handlingStrategy":"validation","validationCode":"Set<Write.Method> supported = EnumSet.of(\n  Write.Method.FILE_LOADS, Write.Method.STREAMING_INSERTS,\n  Write.Method.STORAGE_API_WRAPPER, Write.Method.STORAGE_LOADS, Write.Method.DEFAULT);\nif (writeTransform.getMethod() == null || !supported.contains(writeTransform.getMethod())) {\n  throw new IllegalArgumentException(\"Unsupported BigQuery write method: \" + writeTransform.getMethod());\n}","typeGuard":"static boolean isKnownMethod(Write.Method m) {\n  try { return m != null && Write.Method.valueOf(m.name()) != null; } catch (IllegalArgumentException e) { return false; }\n}","tryCatchPattern":"try {\n  input.apply(\"BQ\", writeTransform);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Unexpected write method\")) {\n    throw new IllegalStateException(\"Set .withMethod() to a supported BigQueryIO.Write.Method enum value\", e);\n  } else { throw e; }\n}","preventionTips":["Only use BigQueryIO.Write.Method enum constants from your Beam version; never string-built or custom methods.","Log getMethod() during pipeline construction to catch regressions early.","After upgrading Beam, re-check any code that set methods programmatically or via reflection."],"tags":["java","bigquery","apache-beam","invalid-enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}