[
https://issues.apache.org/jira/browse/IO-639?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Gary D. Gregory resolved IO-639.
--------------------------------
Fix Version/s: 2.22.0
Resolution: Fixed
> ReversedLinesFileReader does not read first line if it's empty
> --------------------------------------------------------------
>
> Key: IO-639
> URL: https://issues.apache.org/jira/browse/IO-639
> Project: Commons IO
> Issue Type: Bug
> Affects Versions: 2.6
> Reporter: Mashrur Mia
> Priority: Minor
> Fix For: 2.22.0
>
>
> ReversedLinesFileReader does not seem to read the first if the the line is
> empty. Consider the content of a file:
> {code}
> \n
> test\n
> {code}
> where the first line is simple a newline character. If
> ReversedLinesFileReader is used to read the file in reverse, then only the
> 2nd line is read - in the subsequent call, {{::readLine}} return null.
> Here is a Java test that was tried:
> {code:java}
> class ReversedFileReaderTest {
> @ParameterizedTest
> @MethodSource("contentAndExpectedProvider")
> void testReadLineInReverse_givenTwoLines(String content, List<String>
> expected)
> throws IOException {
> File file = Files.newTemporaryFile();
> java.nio.file.Files.write(Path.of(file.getPath()),
> content.getBytes());
> List<String> lines = new ArrayList<>();
> try (ReversedLinesFileReader fileReader = new
> ReversedLinesFileReader(file,
> StandardCharsets.UTF_8)) {
> String line;
> while ((line = fileReader.readLine()) != null) {
> lines.add(line);
> }
> }
> assertThat(lines).isEqualTo(expected);
> }
> static Stream<Arguments> contentAndExpectedProvider() {
> return Stream.of(
> arguments("the\ntest\n", Arrays.asList("test", "the")),
> arguments("\ntest\n", Arrays.asList("test", "")),
> arguments("\n\ntest\n", Arrays.asList("test", "", "")),
> arguments("\n\n", Arrays.asList("", "")),
> arguments("\n", Arrays.asList(""))
> );
> }
> }
> {code}
> Only the first test case runs. All the last four fails
--
This message was sent by Atlassian Jira
(v8.20.10#820010)