[
https://issues.apache.org/jira/browse/HDFS-17848?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18063973#comment-18063973
]
ASF GitHub Bot commented on HDFS-17848:
---------------------------------------
balodesecurity opened a new pull request, #8327:
URL: https://github.com/apache/hadoop/pull/8327
## Summary
`PBImageXmlWriter` and `FileDistributionCalculator` in the Offline Image
Viewer (OIV) currently accept a `PrintStream` and call `print()`/`println()`.
`PrintStream` silently swallows `IOException`s — errors are only detectable
after the fact via `checkError()`, which can miss failures entirely.
This patch replaces `PrintStream` with `java.io.Writer` in both classes so
that write errors propagate immediately as `IOException`.
- Replace `PrintStream out` field with `Writer out` in `PBImageXmlWriter`
and `FileDistributionCalculator`
- Convert all `out.print(x)` → `out.write(x)` and `out.println(x)` →
`out.write(x + "\n")`
- Add `throws IOException` to private helper methods in `PBImageXmlWriter`
that call `out.write()`
- `OfflineImageViewerPB` bridges the gap by wrapping the output
`PrintStream` in an `OutputStreamWriter` (with explicit `flush()` after
`visit()` to drain the buffer)
- Update all test call sites to pass `new OutputStreamWriter(ps,
StandardCharsets.UTF_8)` instead of a raw `PrintStream`
## Test plan
- [x] `TestOfflineImageViewer` — 29 tests pass (includes
`testReverseXmlRoundTrip`, `testCorruptionDetection*`,
`testOfflineImageViewerWithFormatOption`, `testFileDistributionCalculator*`)
- [x] `TestOfflineImageViewerForAcl` — 3 tests pass
- [x] `TestSnapshot#testOfflineImageViewer` — passes
> OIV should not use PrintStream
> ------------------------------
>
> Key: HDFS-17848
> URL: https://issues.apache.org/jira/browse/HDFS-17848
> Project: Hadoop HDFS
> Issue Type: Improvement
> Components: command
> Reporter: Tsz-wo Sze
> Priority: Major
>
> The problem reported by HDFS-17847 actually is due to the use of PrintStream
> in OIV.
> {quote}... Unlike other output streams, a PrintStream never throws an
> IOException; instead, exceptional situations merely set an internal flag that
> can be tested via the checkError method. ...
> {quote} - [https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html]
> As described in the javadoc above, PrintStream never throws an IOException.
> HDFS-17847 has proposed a quick fix by calling the checkError method.
> However, the checkError method does not tell the detail of the error.
> In the use case of OIV, it is better to use a class which throws IOException
> on failures. A potential replacement is
> [OutputStreamWriter|https://docs.oracle.com/javase/8/docs/api/java/io/OutputStreamWriter.html].
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]