RFR: 8358533: Improve performance of java.io.Reader.readAllLines [v4]

Xueming Shen sherman at openjdk.org
Wed Jun 25 20:00:29 UTC 2025


On Tue, 24 Jun 2025 18:51:04 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Right, the specification here requires an unmodifiable List, so an unmodifiable wrapper or a list from `List.copyOf()` is appropriate.
>
> Fixed in [d5abfa4](https://github.com/openjdk/jdk/pull/25863/commits/d5abfa450cb3fcd604560833038735e41952bce9
> ).

My apologies if this is a naive question :-) I'm sure this was discussed when the method was added, so this is just for my own education.

What's the benefit of explicitly specifying that the returned list is unmodifiable here? For example, Files.readAllLines() says that whether the list is modifiable is implementation-dependent and not specified.

In this case, it seems the returned list is a final result — a snapshot — and there's no real harm (to the reader) even if the caller modifies it. So is marking it unmodifiable more of a design philosophy?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25863#discussion_r2167512639


More information about the core-libs-dev mailing list