{"record":{"id":"a2622d541696e1fe","repo":"apache/beam","slug":"caller-does-not-own-the-underlying-input-stream-and-should-a2622d","errorCode":null,"errorMessage":"Caller does not own the underlying input stream  and should not call mark().","messagePattern":"Caller does not own the underlying input stream  and should not call mark\\(\\)\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/UnownedInputStream.java","lineNumber":61,"sourceCode":"  public void close() throws IOException {\n    throw new UnsupportedOperationException(\n        \"Caller does not own the underlying input stream \" + \" and should not call close().\");\n  }\n\n  @Override\n  public boolean equals(@Nullable Object obj) {\n    return obj instanceof UnownedInputStream && ((UnownedInputStream) obj).in.equals(in);\n  }\n\n  @Override\n  public int hashCode() {\n    return in.hashCode();\n  }\n\n  @SuppressWarnings(\"UnsynchronizedOverridesSynchronized\")\n  @Override\n  public void mark(int readlimit) {\n    throw new UnsupportedOperationException(\n        \"Caller does not own the underlying input stream \" + \" and should not call mark().\");\n  }\n\n  @Override\n  public boolean markSupported() {\n    return false;\n  }\n\n  @SuppressWarnings(\"UnsynchronizedOverridesSynchronized\")\n  @Override\n  public void reset() throws IOException {\n    throw new UnsupportedOperationException(\n        \"Caller does not own the underlying input stream \" + \" and should not call reset().\");\n  }\n\n  @Override\n  public String toString() {\n    return MoreObjects.toStringHelper(UnownedInputStream.class).add(\"in\", in).toString();","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/UnownedInputStream.java#L43-L79","documentation":"UnownedInputStream.mark() also throws UnsupportedOperationException because the wrapper cannot safely delegate mark/reset for a stream it does not own (mark/reset state would leak to the real owner). markSupported() returns false. Callers must not attempt to mark positions on this stream.","triggerScenarios":"Calling mark(readlimit) on an UnownedInputStream, or using helper code that calls mark() unconditionally (some parsers/buffer utilities call mark first if not guarded by markSupported()).","commonSituations":"Handing an UnownedInputStream to libraries that use mark/reset (e.g. some JSON/XML parsers, PushbackInputStream patterns) without checking markSupported(), causing runtime failure during parsing.","solutions":["Do not call mark() on UnownedInputStream; buffer the data yourself (e.g. read into a byte[]/ByteArrayInputStream) if lookahead is needed.","Guard any mark usage with markSupported(), which returns false for this wrapper.","If mark/reset is required, copy the underlying owned stream into a BufferedInputStream or ByteArrayInputStream that you own and wrap that.","Use PushbackInputStream around the owned stream at the ownership boundary instead of marking the wrapper."],"exampleFix":"// before\nin.mark(1024); // throws UnsupportedOperationException\nint c = in.read();\nin.reset();\n// after\nif (in.markSupported()) {\n  in.mark(1024);\n}\nInputStream buffered = new BufferedInputStream(new UnownedInputStream(owned)); // or buffer bytes yourself\nbuffered.mark(1024);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"boolean supportsMarking(InputStream in) {\n  return in.markSupported();\n}","tryCatchPattern":"try {\n  in.mark(limit);\n} catch (UnsupportedOperationException e) {\n  // fall back to buffering bytes manually\n}","preventionTips":["Always check markSupported() before calling mark().","Wrap in BufferedInputStream or copy to ByteArrayInputStream when lookahead is needed.","Avoid feeding non-marking streams to parsers that require mark/reset without verifying support."],"tags":["beam","io","stream","mark-reset"],"backgroundTag":"unsupported-operation","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"}