Skip to content

Commit

Permalink
Remove setUnsignedArrayAttribute zero-length-array check
Browse files Browse the repository at this point in the history
This function was omitted from PR samtools#1194. Zero-length 'B' arrays
are valid, so remove this check too and add a test case.
  • Loading branch information
jmarshall committed Jun 13, 2023
1 parent 6d3fc7b commit 1cc8a2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/main/java/htsjdk/samtools/SAMRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -1541,9 +1541,6 @@ public void setUnsignedArrayAttribute(final String tag, final Object value) {
if (!value.getClass().isArray()) {
throw new IllegalArgumentException("Non-array passed to setUnsignedArrayAttribute for tag " + tag);
}
if (Array.getLength(value) == 0) {
throw new IllegalArgumentException("Empty array passed to setUnsignedArrayAttribute for tag " + tag);
}
setAttribute(SAMTag.makeBinaryTag(tag), value, true);
}

Expand Down
13 changes: 13 additions & 0 deletions src/test/java/htsjdk/samtools/SAMRecordUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,19 @@ public void test_setAttribute_empty_array() {
Assert.assertNull(record.getStringAttribute(ARRAY_TAG));
}

@Test
public void test_setUnsignedArrayAttribute_empty_array() {
final SAMFileHeader header = new SAMFileHeader();
final SAMRecord record = new SAMRecord(header);
Assert.assertNull(record.getStringAttribute(ARRAY_TAG));
record.setUnsignedArrayAttribute(ARRAY_TAG, new int[0]);
Assert.assertNotNull(record.getUnsignedIntArrayAttribute(ARRAY_TAG));
Assert.assertEquals(record.getUnsignedIntArrayAttribute(ARRAY_TAG), new int[0]);
Assert.assertEquals(record.getAttribute(ARRAY_TAG), new char[0]);
record.setAttribute(ARRAY_TAG, null);
Assert.assertNull(record.getStringAttribute(ARRAY_TAG));
}

private static Object[][] getEmptyArrays() {
return new Object[][]{
{new int[0], int[].class},
Expand Down

0 comments on commit 1cc8a2c

Please sign in to comment.