Skip to content

Commit

Permalink
IndexFeatureFile: fix a crash on VCFs with 0 records (#5795)
Browse files Browse the repository at this point in the history
Resolves #4269
  • Loading branch information
droazen authored Mar 13, 2019
1 parent 5c46cb8 commit 4ba5170
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
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

0 comments on commit 4ba5170

Please sign in to comment.