[IO-782] SequenceReader should close readers when its close method is called#391
Conversation
Codecov Report
@@ Coverage Diff @@
## master #391 +/- ##
============================================
- Coverage 86.18% 86.08% -0.10%
+ Complexity 3214 3213 -1
============================================
Files 215 215
Lines 7490 7503 +13
Branches 906 908 +2
============================================
+ Hits 6455 6459 +4
- Misses 791 797 +6
- Partials 244 247 +3
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
6e357a9 to
bbd7a98
Compare
garydgregory
left a comment
There was a problem hiding this comment.
I don't think I agree with the premise of this PR: the class did not allocate the resources, so it has no business closing them, it does not own these resources.
What does the community think?
bbd7a98 to
22d2bdc
Compare
|
I checked for example |
|
@digiovinazzo |
| assertEquals('A', sequenceReader.read()); | ||
| assertEquals(EOF, sequenceReader.read()); | ||
| } catch (IOException e) { | ||
| fail("No IOException expected"); |
There was a problem hiding this comment.
Why not just let the exception percolate to fail the test?
There was a problem hiding this comment.
That's another option, it was just to have a meaningful message on fail
There was a problem hiding this comment.
Simpler is better:
try (SequenceReader sequenceReader = new SequenceReader(reader1, emptyReader)) {
assertEquals('A', sequenceReader.read());
assertEquals(EOF, sequenceReader.read());
} finally {
assertTrue(closeEmptyReader.get());
assertTrue(closeReader1.get());
}
22d2bdc to
33da613
Compare
| try { | ||
| reader.close(); | ||
| } catch (IOException e) { | ||
| ioExceptionList.add(e); |
There was a problem hiding this comment.
I'm not sure about the semantics here, which are completely different from SequenceInputStream. For good or bad, I think it would be better for the closing logic of this class to match SequenceInputStream.
|
|
||
| private Reader reader; | ||
| private Iterator<? extends Reader> readers; | ||
| private Iterable<? extends Reader> readersIterable; |
There was a problem hiding this comment.
No need to change the name, it makes the PR noisier.
| final AtomicBoolean closeEmptyReader = new AtomicBoolean(false); | ||
| final Reader emptyReader = new Reader() { | ||
| @Override | ||
| public int read(char[] cbuf, int off, int len) throws IOException { |
|
|
||
| final AtomicBoolean closeReader1 = new AtomicBoolean(false); | ||
| final Reader reader1 = new Reader() { | ||
| private final char[] content = new char[]{'A'}; |
There was a problem hiding this comment.
Use abbreviated notation, IOW ... = {'A'};
| private int position = 0; | ||
|
|
||
| @Override | ||
| public int read(char[] cbuf, int off, int len) throws IOException { |
| } | ||
| }; | ||
|
|
||
| final AtomicBoolean closeReader1 = new AtomicBoolean(false); |
There was a problem hiding this comment.
No need to initialize an AtomicBoolean to false, that's the default, IOW -> new AtomicBoolean();
| assertEquals('A', sequenceReader.read()); | ||
| assertEquals(EOF, sequenceReader.read()); | ||
| } catch (IOException e) { | ||
| fail("No IOException expected"); |
There was a problem hiding this comment.
Simpler is better:
try (SequenceReader sequenceReader = new SequenceReader(reader1, emptyReader)) {
assertEquals('A', sequenceReader.read());
assertEquals(EOF, sequenceReader.read());
} finally {
assertTrue(closeEmptyReader.get());
assertTrue(closeReader1.get());
}
|
The issue is now resolved in git master by making the implementation closer to what |
|
Closing per my previous comment and no feedback in 4 days. |
|
I was offline last week, @garydgregory thanks for taking care of this! |
Pull request to fix https://issues.apache.org/jira/browse/IO-782