On Mon, 2 Dec 2024 14:03:10 GMT, Jaikiran Pai <[email protected]> wrote:
>> src/java.base/linux/classes/jdk/internal/platform/CgroupSubsystemController.java
>> line 70:
>>
>>> 68: String line = bufferedReader.readLine();
>>> 69: return line;
>>> 70: } catch (IOException e) {
>>
>> We can use `Files.lines` here right away:
>>
>> Suggestion:
>>
>> try (Stream<String> lines = Files.lines(filePath)) {
>> Optional<String> firstLine = lines.findFirst();
>> return firstLine.orElse(null);
>> } catch (UncheckedIOException | IOException e) {
>
> Is the catch for `UncheckedIOException` due to some previously known failure
> resulting in the use of these APIs?
Without using `Files.lines()` no `UncheckedIOException` would be thrown. Just
`IOException` and `null` returned. This extra catch is there to avoid new
`UncheckedIOException` being thrown on `findFirst()`. I.e. to keep semantics
the same as before.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22478#discussion_r1865913984