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
This commit is contained in:
Glen Stampoultzis 2003-07-13 13:51:53 +00:00
parent f719da9ca8
commit fd7e42b9d3
2 changed files with 6 additions and 1 deletions

View File

@ -109,12 +109,14 @@ public class HexDump
throws IOException, ArrayIndexOutOfBoundsException, throws IOException, ArrayIndexOutOfBoundsException,
IllegalArgumentException IllegalArgumentException
{ {
if ((index < 0) || (index >= data.length)) if ((index < 0) || (data.length != 0 && index >= data.length))
{ {
throw new ArrayIndexOutOfBoundsException( throw new ArrayIndexOutOfBoundsException(
"illegal index: " + index + " into array of length " "illegal index: " + index + " into array of length "
+ data.length); + data.length);
} }
if (data.length == 0)
return; // nothing more to do.
if (stream == null) if (stream == null)
{ {
throw new IllegalArgumentException("cannot write to nullstream"); throw new IllegalArgumentException("cannot write to nullstream");

View File

@ -314,6 +314,9 @@ public class TestHexDump
// as expected // 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() public void testToHex()