diff --git a/src/java/org/apache/poi/util/HexDump.java b/src/java/org/apache/poi/util/HexDump.java index d45b239bf..74198bc52 100644 --- a/src/java/org/apache/poi/util/HexDump.java +++ b/src/java/org/apache/poi/util/HexDump.java @@ -109,12 +109,14 @@ public class HexDump throws IOException, ArrayIndexOutOfBoundsException, IllegalArgumentException { - if ((index < 0) || (index >= data.length)) + if ((index < 0) || (data.length != 0 && index >= data.length)) { throw new ArrayIndexOutOfBoundsException( "illegal index: " + index + " into array of length " + data.length); } + if (data.length == 0) + return; // nothing more to do. if (stream == null) { throw new IllegalArgumentException("cannot write to nullstream"); diff --git a/src/testcases/org/apache/poi/util/TestHexDump.java b/src/testcases/org/apache/poi/util/TestHexDump.java index 7a86cff76..c8e3ca9e5 100644 --- a/src/testcases/org/apache/poi/util/TestHexDump.java +++ b/src/testcases/org/apache/poi/util/TestHexDump.java @@ -314,6 +314,9 @@ public class TestHexDump // as expected } + + // verify proper behaviour with a 0 length dump on 0 length dataset + HexDump.dump(new byte[0], 0, new ByteArrayOutputStream(), 0, 0); } public void testToHex()