{"record":{"id":"a9a29630489dcf0f","repo":"apache/beam","slug":"gcsseekablebytechannel-are-read-only-and-does-not-support","errorCode":null,"errorMessage":"GcsSeekableByteChannel are read-only and does not support writing.","messagePattern":"GcsSeekableByteChannel are read-only and does not support writing\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/GcsUtilV2.java","lineNumber":545,"sourceCode":"    @Override\n    public long position() throws IOException {\n      return this.position;\n    }\n\n    @Override\n    public long size() throws IOException {\n      return size;\n    }\n\n    @Override\n    public SeekableByteChannel truncate(long size) throws IOException {\n      throw new UnsupportedOperationException(\n          \"GcsSeekableByteChannels are read-only and cannot be truncated.\");\n    }\n\n    @Override\n    public int write(ByteBuffer src) throws IOException {\n      throw new UnsupportedOperationException(\n          \"GcsSeekableByteChannel are read-only and does not support writing.\");\n    }\n\n    @Override\n    public boolean isOpen() {\n      return reader.isOpen();\n    }\n\n    @Override\n    public void close() throws IOException {\n      if (isOpen()) {\n        reader.close();\n      }\n    }\n  }\n\n  public SeekableByteChannel open(GcsPath path, BlobSourceOption... sourceOptions)\n      throws IOException {","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/GcsUtilV2.java#L527-L563","documentation":"GcsSeekableByteChannel returned by GcsUtilV2 opens GCS objects in read-only mode; any attempt to write, position for write, or truncate throws UnsupportedOperationException. GCS objects are immutable through this channel abstraction, so writes are intentionally unsupported rather than emulated.","triggerScenarios":"Calling write(ByteBuffer), truncate(long), or position(long) with a value larger than the object size on a channel obtained via GcsUtilV2.open(GcsPath).","commonSituations":"Code written against java.nio.FileChannel semantics (read-modify-write of a remote file) reused on a GCS path; file-copy utilities that open channels with READ|WRITE options.","solutions":["Rewrite the code to only read from the GCS channel","To modify a GCS object, download it, modify locally, and upload a new object (or use the GCS rewrite/compose APIs instead)","Use WriteChannels from GcsUtil/GcsOptions (create(GcsPath)) rather than open() when writing is intended"],"exampleFix":"// before\nSeekableByteChannel ch = gcsUtil.open(path);\nch.write(ByteBuffer.wrap(data)); // throws\n// after\ntry (WriteChannel wc = gcsUtil.create(path)) {\n  wc.write(ByteBuffer.wrap(data));\n}","handlingStrategy":"validation","validationCode":"if (channel instanceof GcsSeekableByteChannel || gcsPath != null && channelMode == Mode.READ) { /* never call write/truncate */ }","typeGuard":"boolean isWritableChannel(SeekableByteChannel ch) { return !(ch instanceof GcsSeekableByteChannel); }","tryCatchPattern":null,"preventionTips":["Treat channels from GcsUtil.open() as strictly read-only","Use GcsUtil.create()/WriteChannel for writes","Add unit tests asserting no write paths touch read-only GCS channels"],"tags":["gcs","java","unsupported-operation","read-only"],"backgroundTag":"unsupported-operation","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"}