{"record":{"id":"8050619b584af2ea","repo":"prestodb/presto","slug":"failed-to-close-bytearrayoutputstream","errorCode":null,"errorMessage":"Failed to close ByteArrayOutputStream","messagePattern":"Failed to close ByteArrayOutputStream","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"warning","filePath":"presto-kafka/src/main/java/com/facebook/presto/kafka/encoder/avro/AvroRowEncoder.java","lineNumber":157,"sourceCode":"            dataFileWriter.append(record);\n            dataFileWriter.close();\n\n            resetColumnIndex(); // reset currentColumnIndex to prepare for next row\n            return byteArrayOutputStream.toByteArray();\n        }\n        catch (IOException e) {\n            throw new UncheckedIOException(\"Failed to append record\", e);\n        }\n    }\n\n    @Override\n    public void close()\n    {\n        try {\n            byteArrayOutputStream.close();\n        }\n        catch (IOException e) {\n            throw new UncheckedIOException(\"Failed to close ByteArrayOutputStream\", e);\n        }\n    }\n}\n","sourceCodeStart":139,"sourceCodeEnd":161,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-kafka/src/main/java/com/facebook/presto/kafka/encoder/avro/AvroRowEncoder.java#L139-L161","documentation":"AvroRowEncoder.close() wraps any IOException thrown while closing the underlying ByteArrayOutputStream into an UncheckedIOException. ByteArrayOutputStream.close() is documented as a no-op and practically never throws, so this guard exists purely to satisfy the Closeable contract of the RowEncoder interface and shield callers from checked exceptions.","triggerScenarios":"Calling close() on an AvroRowEncoder after encoding rows; the try/catch fires only if byteArrayOutputStream.close() throws an IOException, which for ByteArrayOutputStream effectively never happens.","commonSituations":"Teardown of a Kafka record encoder at the end of a query page; try-with-resources on the encoder; almost always seen only as an impossible defensive branch or during JVM-level I/O errors.","solutions":["No action needed: the underlying ByteArrayOutputStream.close() is a no-op and cannot realistically fail.","If it ever surfaces, inspect the wrapped IOException cause for an unusual OutputStream subclass or agent-decorated stream and fix that resource.","Upgrade Presto, since this defensive wrapper could be simplified/silenced in newer versions."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// close() already wraps into UncheckedIOException; only needed if calling stream.close() directly\ntry {\n    encoder.close();\n} catch (UncheckedIOException e) {\n    log.warn(\"Failed to close AvroRowEncoder: %s\", e.getMessage(), e);\n}","preventionTips":["Rely on ByteArrayOutputStream.close() being a no-op; do not add extra handling.","Close encoders in try-with-resources so teardown errors surface deterministically.","Inspect the chained cause if this error ever actually fires."],"tags":["java","io","kafka","avro","encoder"],"backgroundTag":"stream-close-failed","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}