Skip to content

Write an empty AD or PL to VCF as missing - #1962

Open
nh13 wants to merge 1 commit into
samtools:masterfrom
nh13:nh_vcf_empty_ad_pl
Open

nh13 wants to merge 1 commit into
samtools:masterfrom
nh13:nh_vcf_empty_ad_pl

Conversation

@nh13

@nh13 nh13 commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

The VCF writer threw ArrayIndexOutOfBoundsException in VCFEncoder.appendGenotypeData for a genotype whose AD or PL was an empty array. It now writes ., as the BCF writer already did.

Summary by CodeRabbit

  • Bug Fixes
    • VCF output now writes empty genotype AD and PL values as missing (.), instead of failing during encoding.
    • Empty AD values remain correctly marked as missing when other genotype values are present.

The VCF writer failed with ArrayIndexOutOfBoundsException on a genotype
whose AD or PL was an empty array. It now writes it as `.`, as the BCF
writer already did.
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The VCF encoder now writes empty integer FORMAT arrays as missing (.), matching the existing BCF behavior. New tests cover empty AD and PL values, populated PL values after empty AD, and BCF round-trip behavior. The changelog records the fix.

Changes: Empty genotype FORMAT arrays

Layer / File(s) Summary
Missing-value encoding and validation
src/main/java/htsjdk/variant/vcf/VCFEncoder.java, src/test/java/htsjdk/variant/vcf/VCFEncoderTest.java, src/test/java/htsjdk/variant/bcf2/BCF2WriterUnitTest.java, CHANGELOG.md
The VCF encoder treats null or empty integer FORMAT arrays as missing. VCF tests cover empty AD and PL values, including empty AD followed by populated PL. A BCF round-trip test checks that empty AD is unavailable while another sample’s AD values remain intact. The changelog documents the fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: tfenne

Merge Risk: Minimal · up to 6130e

The VCF writer now writes empty AD or PL arrays as missing (.) instead of throwing ArrayIndexOutOfBoundsException. The change is small and covered by tests for VCF output and a BCF round trip, so it is low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title states the main change: the VCF writer now writes an empty AD or PL array as missing (.). The changeset matches this. The VCFEncoder fix treats an empty array as missing, and the new tests c…
Linked Issues check Passed Objective [#1960]: VCFEncoder.appendGenotypeData must write an empty AD or PL array as missing (.) instead of reading element 0 and throwing ArrayIndexOutOfBoundsException. The whole-PR summary stat…
Out of Scope Changes check Passed All changed files relate to the objective in #1960. VCFEncoder.java holds the fix for empty AD or PL handling. VCFEncoderTest.java holds tests for the VCF output. BCF2WriterUnitTest.java holds a regre…
Full details: Title check

Explanation

The title states the main change: the VCF writer now writes an empty AD or PL array as missing (.). The changeset matches this. The VCFEncoder fix treats an empty array as missing, and the new tests check that behavior.

Full details: Linked Issues check

Explanation

Objective [#1960]: VCFEncoder.appendGenotypeData must write an empty AD or PL array as missing (.) instead of reading element 0 and throwing ArrayIndexOutOfBoundsException. The whole-PR summary states that the integer FORMAT accessor in appendGenotypeData now treats both a null result and an empty array as missing. Before this change, only null was treated as missing. Tests in VCFEncoderTest assert GT:AD / 0/1:., and GT:AD:PL / 0/1:.:10,0,20 for an empty AD followed by a populated PL. BCF2WriterUnitTest.anEmptyAdIsWrittenAsMissing asserts that BCF round-trips an empty AD as missing. The issue's requirement is met by the described change. Limitation: the repository diff tool was unavailable for the changed files, and the encoder code was read only from the supplied summary. The file read was truncated before appendGenotypeData, so the exact code lines were not directly verified.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the objective in #1960. VCFEncoder.java holds the fix for empty AD or PL handling. VCFEncoderTest.java holds tests for the VCF output. BCF2WriterUnitTest.java holds a regression test for the BCF behavior the issue names as the reference. CHANGELOG.md holds a 6.0.1 bug-fix entry for the same change. No unrelated changes were identified in the supplied summary. Limitation: the changed-file diffs could not be read directly, so this assessment relies on the supplied summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1ac8fa4d-ae75-43fb-9f22-3b4b206026ed
Commits

Reviewing files that changed from the base of the PR and between c406c47 and 6130e5a.

Files selected for processing: 4

  • CHANGELOG.md
  • src/main/java/htsjdk/variant/vcf/VCFEncoder.java
  • src/test/java/htsjdk/variant/bcf2/BCF2WriterUnitTest.java
  • src/test/java/htsjdk/variant/vcf/VCFEncoderTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

This branch has not been deployed

No deployments
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.

VCF writer throws ArrayIndexOutOfBoundsException on an empty AD or PL

1 participant