Skip to content

Commit 42f6e64

Browse files
author
Yaniv Inbar
committed
http: better debugging message for ByteArrayContent
https://codereview.appspot.com/8914043/
1 parent 4bb60cd commit 42f6e64

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

google-http-client/src/main/java/com/google/api/client/http/ByteArrayContent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public ByteArrayContent(String type, byte[] array) {
7878
public ByteArrayContent(String type, byte[] array, int offset, int length) {
7979
super(type);
8080
this.byteArray = Preconditions.checkNotNull(array);
81-
Preconditions.checkArgument(offset >= 0 && length >= 0 && offset + length <= array.length);
81+
Preconditions.checkArgument(offset >= 0 && length >= 0 && offset + length <= array.length,
82+
"offset %s, length %s, array length %s", offset, length, array.length);
8283
this.offset = offset;
8384
this.length = length;
8485
}

google-http-client/src/test/java/com/google/api/client/http/ByteArrayContentTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,21 @@ public void testConstructor() throws IOException {
4040
fail("expected " + IllegalArgumentException.class);
4141
} catch (IllegalArgumentException e) {
4242
// expected
43+
assertEquals("offset -1, length 2, array length 3", e.getMessage());
4344
}
4445
try {
4546
new ByteArrayContent(null, FOO, 2, 2);
4647
fail("expected " + IllegalArgumentException.class);
4748
} catch (IllegalArgumentException e) {
4849
// expected
50+
assertEquals("offset 2, length 2, array length 3", e.getMessage());
4951
}
5052
try {
5153
new ByteArrayContent(null, FOO, 3, 1);
5254
fail("expected " + IllegalArgumentException.class);
5355
} catch (IllegalArgumentException e) {
5456
// expected
57+
assertEquals("offset 3, length 1, array length 3", e.getMessage());
5558
}
5659
}
5760

0 commit comments

Comments
 (0)