Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in BlockCompressedInputStream.checkTermination() #1310

Merged
merged 2 commits into from
Mar 4, 2019

Conversation

lbergelson
Copy link
Member

@lbergelson lbergelson commented Feb 28, 2019

  • Fixing a bug in BlockCompressedInputStream.checkTermination()
    The internal method readFully would throw in cases where less bytes were read than were available in the stream.
    We haven't observed this in practice but it's a valid behavior of SeekableByteChannel.read() so we should honor it.
  • Fixes BlockCompressedInputStream.readFully seems likely to be buggy #1251

Description

Please explain the changes you made here.
Explain the motivation for making this change. What existing problem does the pull request solve?

Checklist

  • Code compiles correctly
  • New tests covering changes and new functionality
  • All tests passing
  • Extended the README / documentation, if necessary
  • Is not backward compatible (breaks binary or source compatibility)

* Fixing a bug in BlockCompressedInputStream.checkTermination()
  The internal method readFully would throw in cases where less bytes were read than were available in the stream.
  We haven't observed this in practice but it's a valid behavior of SeekableByteChannel.read() so we should honor it.
* Fixes #1251
@codecov-io
Copy link

codecov-io commented Feb 28, 2019

Codecov Report

Merging #1310 into master will increase coverage by 0.917%.
The diff coverage is 100%.

@@               Coverage Diff               @@
##              master     #1310       +/-   ##
===============================================
+ Coverage     67.728%   68.644%   +0.917%     
- Complexity      8225      8666      +441     
===============================================
  Files            560       562        +2     
  Lines          33493     35311     +1818     
  Branches        5637      6156      +519     
===============================================
+ Hits           22684     24239     +1555     
- Misses          8632      8828      +196     
- Partials        2177      2244       +67
Impacted Files Coverage Δ Complexity Δ
...sjdk/samtools/util/BlockCompressedInputStream.java 85.56% <100%> (+0.265%) 90 <3> (+1) ⬆️
...a/htsjdk/samtools/cram/build/ContainerFactory.java 95.238% <0%> (-1.732%) 9% <0%> (+3%)
...va/htsjdk/samtools/cram/build/ContainerParser.java 95.062% <0%> (-1.235%) 18% <0%> (ø)
...oding/reader/MultiRefSliceAlignmentSpanReader.java 100% <0%> (ø) 10% <0%> (+5%) ⬆️
...ava/htsjdk/samtools/cram/ref/ReferenceContext.java 91.667% <0%> (ø) 22% <0%> (?)
...htsjdk/samtools/cram/ref/ReferenceContextType.java 100% <0%> (ø) 1% <0%> (?)
...jdk/samtools/cram/build/Cram2SamRecordFactory.java 93.22% <0%> (+0.058%) 29% <0%> (ø) ⬇️
src/main/java/htsjdk/samtools/cram/CRAIIndex.java 83.065% <0%> (+0.138%) 41% <0%> (+14%) ⬆️
.../java/htsjdk/samtools/util/IntervalListWriter.java 88.235% <0%> (+0.235%) 6% <0%> (+1%) ⬆️
src/main/java/htsjdk/samtools/util/Interval.java 64.13% <0%> (+0.494%) 43% <0%> (+17%) ⬆️
... and 22 more

final int bytesRead = channel.read(dst);
if (bytesRead < dst.capacity()){
throw new EOFException();
int totalBytesRead = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reformat using IDE to fix whitespace, in all three files.

try(final SeekableByteChannel channel = new OneByteAtATimeChannel(buffer)){
final int readBufferSize = 10;
final ByteBuffer readBuffer = ByteBuffer.allocate(readBufferSize);
// Assert.assertTrue(channel.size() >= readBuffer.capacity());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete or uncomment commented code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -77,6 +77,10 @@ public void close() throws IOException {
open = false;
}

protected ByteBuffer getBuffer(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a shame to expose this for testing purposes only. If the subclass type was defined in the same package, you could use package (default) scope instead, which is more restrictive than protected, and doesn't lead to API compatibility requirements later on.

So you could use default scope here if you defined OneByteAtATimeChannel in the same package as SeekableByteChannelFromBuffer. You could put the source in the test directory so it wouldn't be part of the public API.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is already in the test directories so it isn't part of the public API. I don't mind moving them both to a subpackage though and restricting it to default scope.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved both to htsjdk.testutil.streams

@lbergelson lbergelson self-assigned this Mar 4, 2019
@lbergelson lbergelson merged commit d678af3 into master Mar 4, 2019
@lbergelson lbergelson deleted the lb_fix_readfully_bug branch March 4, 2019 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants