Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-2984eeb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWS SDK for Java v2",
"contributor": "faucct",
"description": "Fix `InputStreamSubscriber` to return 0 when reading a length of 0."
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public int read(byte[] b) {

@Override
public int read(byte[] bytes, int off, int len) {
if (len == 0) {
return 0;
}

ByteBuffer byteBuffer = ByteBuffer.wrap(bytes, off, len);
TransferResult transferResult = delegate.blockingTransferTo(byteBuffer);
int dataTransferred = byteBuffer.position() - off;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public void onComplete_returnsEndOfStream_onRead() {
publisher.subscribe(subscriber);
publisher.complete();
assertThat(subscriber.read()).isEqualTo(-1);
assertThat(subscriber.read(new byte[0])).isEqualTo(-1);
assertThat(subscriber.read(new byte[0], 0, 0)).isEqualTo(-1);
assertThat(subscriber.read(new byte[1])).isEqualTo(-1);
assertThat(subscriber.read(new byte[1], 0, 1)).isEqualTo(-1);
}

@Test
Expand All @@ -69,8 +69,8 @@ public void onError_throws_onRead() {
publisher.subscribe(subscriber);
publisher.error(exception);
assertThatThrownBy(() -> subscriber.read()).isEqualTo(exception);
assertThatThrownBy(() -> subscriber.read(new byte[0])).isEqualTo(exception);
assertThatThrownBy(() -> subscriber.read(new byte[0], 0, 0)).isEqualTo(exception);
assertThatThrownBy(() -> subscriber.read(new byte[1])).isEqualTo(exception);
assertThatThrownBy(() -> subscriber.read(new byte[1], 0, 1)).isEqualTo(exception);
}

@Test
Expand Down Expand Up @@ -128,8 +128,15 @@ public void read_afterClose_fails() {
publisher.subscribe(subscriber);
subscriber.close();
assertThatThrownBy(() -> subscriber.read()).isInstanceOf(CancellationException.class);
assertThatThrownBy(() -> subscriber.read(new byte[0])).isInstanceOf(CancellationException.class);
assertThatThrownBy(() -> subscriber.read(new byte[0], 0, 0)).isInstanceOf(CancellationException.class);
assertThatThrownBy(() -> subscriber.read(new byte[1])).isInstanceOf(CancellationException.class);
assertThatThrownBy(() -> subscriber.read(new byte[1], 0, 1)).isInstanceOf(CancellationException.class);
}

@Test
public void readByteArray_0Len_returns0() {
publisher.subscribe(subscriber);

assertThat(subscriber.read(new byte[1], 0, 0)).isEqualTo(0);
}

public static List<Arguments> stochastic_methodCallsSeemThreadSafe_parameters() {
Expand Down