Skip to content

Commit 58bb655

Browse files
author
Brian Burkhalter
committed
8222329: Readable read(CharBuffer) does not specify that 0 is returned when there is no remaining space in buffer
Reviewed-by: rriggs, lancea, alanb
1 parent 05e9c41 commit 58bb655

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

src/java.base/share/classes/java/io/Reader.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,18 @@ protected Reader(Object lock) {
189189
* Attempts to read characters into the specified character buffer.
190190
* The buffer is used as a repository of characters as-is: the only
191191
* changes made are the results of a put operation. No flipping or
192-
* rewinding of the buffer is performed.
192+
* rewinding of the buffer is performed. If the {@linkplain
193+
* java.nio.CharBuffer#length length} of the specified character
194+
* buffer is zero, then no characters will be read and zero will be
195+
* returned.
193196
*
194197
* @param target the buffer to read characters into
195-
* @return The number of characters added to the buffer, or
196-
* -1 if this source of characters is at its end
198+
* @return The number of characters added to the buffer,
199+
* possibly zero, or -1 if this source of characters is at its end
197200
* @throws IOException if an I/O error occurs
198201
* @throws NullPointerException if target is null
199-
* @throws java.nio.ReadOnlyBufferException if target is a read only buffer
202+
* @throws java.nio.ReadOnlyBufferException if target is a read only buffer,
203+
* even if its length is zero
200204
* @since 1.5
201205
*/
202206
public int read(CharBuffer target) throws IOException {

src/java.base/share/classes/java/lang/Readable.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,14 +40,18 @@ public interface Readable {
4040
* Attempts to read characters into the specified character buffer.
4141
* The buffer is used as a repository of characters as-is: the only
4242
* changes made are the results of a put operation. No flipping or
43-
* rewinding of the buffer is performed.
43+
* rewinding of the buffer is performed. If the {@linkplain
44+
* java.nio.CharBuffer#length length} of the specified character
45+
* buffer is zero, then no characters will be read and zero will be
46+
* returned.
4447
*
4548
* @param cb the buffer to read characters into
4649
* @return The number of {@code char} values added to the buffer,
47-
* or -1 if this source of characters is at its end
50+
* possibly zero, or -1 if this source of characters is at its end
4851
* @throws IOException if an I/O error occurs
4952
* @throws NullPointerException if cb is null
50-
* @throws java.nio.ReadOnlyBufferException if cb is a read only buffer
53+
* @throws java.nio.ReadOnlyBufferException if cb is a read only buffer,
54+
* even if its length is zero
5155
*/
5256
public int read(java.nio.CharBuffer cb) throws IOException;
5357
}

src/java.base/share/classes/java/nio/X-Buffer.java.template

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,16 @@ public abstract sealed class $Type$Buffer
471471
* Attempts to read characters into the specified character buffer.
472472
* The buffer is used as a repository of characters as-is: the only
473473
* changes made are the results of a put operation. No flipping or
474-
* rewinding of the buffer is performed.
474+
* rewinding of the buffer is performed. If the {@linkplain #length
475+
* length} of the specified character buffer is zero, then no characters
476+
* will be read and zero will be returned.
475477
*
476478
* @param target the buffer to read characters into
477-
* @return The number of characters added to the buffer, or
478-
* -1 if this source of characters is at its end
479+
* @return The number of characters added to the buffer,
480+
* possibly zero, or -1 if this source of characters is at its end
479481
* @throws IOException if an I/O error occurs
480-
* @throws ReadOnlyBufferException if target is a read only buffer
482+
* @throws ReadOnlyBufferException if target is a read only buffer,
483+
* even if its length is zero
481484
* @since 1.5
482485
*/
483486
public int read(CharBuffer target) throws IOException {

0 commit comments

Comments
 (0)