Skip to content

Commit

Permalink
Merge pull request #190 from ariksher-nex/master
Browse files Browse the repository at this point in the history
AsciiSequenceView avoid NullPointerException at getBytes
  • Loading branch information
mjpt777 authored Nov 18, 2019
2 parents 9d840ff + 81bb36b commit a3afd46
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions agrona/src/main/java/org/agrona/AsciiSequenceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,17 @@ public void reset()
*/
public int getBytes(final MutableDirectBuffer dstBuffer, final int dstOffset)
{
dstBuffer.putBytes(dstOffset, this.buffer, offset, length);
if (null == buffer || length <= 0)
{
return 0;
}
dstBuffer.putBytes(dstOffset, buffer, offset, length);
return length;
}

public String toString()
{
if (null == buffer)
if (null == buffer || length <= 0)
{
return "";
}
Expand Down
1 change: 1 addition & 0 deletions agrona/src/test/java/org/agrona/AsciiSequenceViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void shouldReturnEmptyStringWhenBufferIsNull()
{
assertEquals(0, asciiSequenceView.length());
assertEquals("", asciiSequenceView.toString());
assertEquals(0, asciiSequenceView.getBytes(new UnsafeBuffer(new byte[128]), 16));
}

@Test(expected = StringIndexOutOfBoundsException.class)
Expand Down

0 comments on commit a3afd46

Please sign in to comment.