From be515c0999d39c90be570e00e26da15603fe056a Mon Sep 17 00:00:00 2001 From: David Roazen Date: Wed, 13 Mar 2019 12:36:12 -0400 Subject: [PATCH] IndexFeatureFile: fix a crash on VCFs with 0 records Resolves #4269 --- .../codecs/ProgressReportingDelegatingCodec.java | 6 +++++- .../tools/IndexFeatureFileIntegrationTest.java | 16 ++++++++++++++++ .../tools/IndexFeatureFile/header_only.vcf | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/org/broadinstitute/hellbender/tools/IndexFeatureFile/header_only.vcf diff --git a/src/main/java/org/broadinstitute/hellbender/utils/codecs/ProgressReportingDelegatingCodec.java b/src/main/java/org/broadinstitute/hellbender/utils/codecs/ProgressReportingDelegatingCodec.java index 78b818d74cc..6114aaaf3ce 100644 --- a/src/main/java/org/broadinstitute/hellbender/utils/codecs/ProgressReportingDelegatingCodec.java +++ b/src/main/java/org/broadinstitute/hellbender/utils/codecs/ProgressReportingDelegatingCodec.java @@ -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; } diff --git a/src/test/java/org/broadinstitute/hellbender/tools/IndexFeatureFileIntegrationTest.java b/src/test/java/org/broadinstitute/hellbender/tools/IndexFeatureFileIntegrationTest.java index 4922e656210..09c6132250d 100644 --- a/src/test/java/org/broadinstitute/hellbender/tools/IndexFeatureFileIntegrationTest.java +++ b/src/test/java/org/broadinstitute/hellbender/tools/IndexFeatureFileIntegrationTest.java @@ -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); + } } diff --git a/src/test/resources/org/broadinstitute/hellbender/tools/IndexFeatureFile/header_only.vcf b/src/test/resources/org/broadinstitute/hellbender/tools/IndexFeatureFile/header_only.vcf new file mode 100644 index 00000000000..97ce5e4dde0 --- /dev/null +++ b/src/test/resources/org/broadinstitute/hellbender/tools/IndexFeatureFile/header_only.vcf @@ -0,0 +1,2 @@ +##fileformat=VCFv4.1 +#CHROM POS ID REF ALT QUAL FILTER INFO