On Thu, 19 Jun 2025 11:08:32 GMT, Markus KARG <d...@openjdk.org> wrote:

>> Replaces the implementation `readAllCharsAsString().lines().toList()` with 
>> reading into a temporary `char` array which is then processed to detect line 
>> terminators and copy non-terminating characters into strings which are added 
>> to the list.
>
> src/java.base/share/classes/java/io/Reader.java line 508:
> 
>> 506:         }
>> 507: 
>> 508:         return lines;
> 
> Do we really want to return a mutable `ArrayList` here? In earlier 
> discussions about this very API I was told that it deliberately returns 
> `String` instead of `CharSequence` due to *intended* immutability, even if 
> that potentially implied slower performance. Following this logic, it would 
> be just straightforward to `return Collections.unmodifiableList(lines);` 
> here. 🤔

Right, the specification here requires an unmodifiable List, so an unmodifiable 
wrapper or a list from `List.copyOf()` is appropriate.

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

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

Reply via email to