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

IndexFeatureFile: fix a crash on VCFs with 0 records #5795

Merged
merged 1 commit into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ public boolean isDone(final B b) {
throw new IllegalStateException("this codec cannot be used without a delegatee.");
}
final boolean done = delegatee.isDone(b);
if (done){

// Make sure the progress meter has been started before trying to stop it (it might not
// have been started if there were 0 records in the file):
if (done && pm.started()){
pm.stop();
}

return done;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,20 @@ public void testVCFIndex_cannotWrite() {
};
final Object res = this.runCommandLine(args);
}

// Make sure we can index a VCF with 0 records without crashing:
@Test
public void testVCFWithNoRecords() {
final File emptyVCF = getTestFile("header_only.vcf");
final File output = createTempFile("header_only.vcf", ".idx");

final String[] args = {
"--feature-file", emptyVCF.getAbsolutePath(),
"-O", output.getAbsolutePath()
};
runCommandLine(args);

Assert.assertTrue(output.exists());
Assert.assertTrue(output.length() > 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
##fileformat=VCFv4.1
#CHROM POS ID REF ALT QUAL FILTER INFO