From fd7e42b9d3ccf940a327fd87d36bf416bb22e3e2 Mon Sep 17 00:00:00 2001 From: Glen Stampoultzis Date: Sun, 13 Jul 2003 13:51:53 +0000 Subject: [PATCH] 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 --- src/java/org/apache/poi/util/HexDump.java | 4 +++- src/testcases/org/apache/poi/util/TestHexDump.java | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) 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()