From: Glen Stampoultzis Date: Sun, 13 Jul 2003 13:51:53 +0000 (+0000) Subject: Fixed a small problem with hex dump X-Git-Tag: REL_2_5_1~110 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=81cb9fe7390bfb6a946108ed05be1305694fd9eb;p=poi.git Fixed a small problem with hex dump git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/REL_2_BRANCH@353209 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/util/HexDump.java b/src/java/org/apache/poi/util/HexDump.java index d45b239bf7..74198bc525 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 7a86cff764..c8e3ca9e5c 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()