Skip to content

Commit 162a20a

Browse files
stuartwdouglasgregw
andcommitted
Apply suggestions from code review
Co-authored-by: Greg Wilkins <gregw@webtide.com>
1 parent d7fbce3 commit 162a20a

File tree

3 files changed

+43
-35
lines changed

3 files changed

+43
-35
lines changed

api/src/main/java/jakarta/servlet/ReadListener.java

+16-13
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,22 @@ public interface ReadListener extends EventListener {
5050
void onAllDataRead() throws IOException;
5151

5252
/**
53-
* Invoked when an error occurs reading data. This listener will be invoked if there is a problem with the underlying
54-
* connection while data is being read from the stream. We consider data to be being read when the following conditions
55-
* are met:
56-
*
57-
* <ul>
58-
* <li>{@link ServletInputStream#isReady()} has been invoked and returned false</li>
59-
* <li>{@link ServletInputStream#close()} has not been called</li>
60-
* <li>{@link ServletInputStream#read()} (or any other read method) has not returned {@code -1}</li>
61-
* </ul>
62-
*
63-
* If these conditions are not met and the stream is still open then any failure notification will not be delivered
64-
* until {@link ServletInputStream#isReady()} is invoked. {@code isReady} must return false in this situation, and then
65-
* the failure will be delivered to this method.
53+
* Invoked when an error occurs reading data after {@link #setReadListener(ReadListener)}
54+
* has been called. This method will be invoked if there is a problem while data is being
55+
* read from the stream and either:
56+
* <ul>
57+
* <li>{@link ServletInputStream#isReady()} has been invoked and returned false;</li>
58+
* <li>or {@link ServletInputStream#close()} has been called, and the failure occurred
59+
* before the response could be completed</li>
60+
* </ul>
61+
* If these conditions are not met and the stream is still open then any failure
62+
* notification will be delivered either:
63+
* by an exception thrown from a {@code IO} operation after an invocation of
64+
* {@link ServletInputStream#isReady()} has returned {@code true}; or by a call to this method
65+
* after an invocation of {@link ServletInputStream#isReady()} has returned {@code false};
66+
* <p>
67+
* This method will not be invoked in any circumstances after
68+
* {@link AsyncListener#onComplete(AsyncEvent)} has been called.
6669
*
6770
* @param t the throwable to indicate why the read operation failed
6871
*/

api/src/main/java/jakarta/servlet/ServletInputStream.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,13 @@ public int readLine(byte[] b, int off, int len) throws IOException {
178178
* If an attempt is made to read from the stream when the stream is in async mode and this method has not returned
179179
* {@code true} the method will throw an {@link IllegalStateException}.
180180
* <p>
181-
* If an error occurs and {@link ReadListener#onError(Throwable)} is invoked then this method will always return false,
182-
* as no further IO operations are allowed after {@code onError} notification.
181+
* If an error occurs then either: this method will return {@code true} and
182+
* an {@link IOException} will be thrown from a subsequent call to {@code read(...)};
183+
* or this method will return {@code false} and subsequently {@link ReadListener#onError(Throwable)}
184+
* will be invoked with the error. Once the error has either been thrown or passed to
185+
* {@link ReadListener#onError(Throwable)}, then this method will always return {@code true} and all
186+
* further {@code read} operations will throw an {@link IOException}.
183187
* <p>
184-
* Note that due to the requirement for {@code read} to never throw in async mode, this method must return false if a
185-
* call to {@code read} would result in an exception.
186188
*
187189
* @return {@code true} if data can be obtained without blocking, otherwise returns {@code false}.
188190
* @see ReadListener
@@ -194,11 +196,11 @@ public int readLine(byte[] b, int off, int len) throws IOException {
194196
* Instructs the <code>ServletInputStream</code> to invoke the provided {@link ReadListener} when it is possible to
195197
* read.
196198
* <p>
197-
* Note that after this method has been called methods on this stream that are documented to throw {@link IOException}
198-
* will no longer throw these exceptions directly, instead any exception that occurs will be reported via
199-
* {@link ReadListener#onError(Throwable)}. Please refer to this method for more information. This only applies to
200-
* {@code IOException}, other exception types may still be thrown (e.g. methods can throw {@link IllegalStateException}
201-
* if {@link #isReady()} has not returned true).
199+
* Note that after this method has been called, methods on this stream that are documented
200+
* to throw {@link IOException} might not throw these exceptions directly,
201+
* instead they may be reported via {@link ReadListener#onError(Throwable)} after a call to
202+
* {@link #isReady()} has returned {@code false}.
203+
* Please refer to {@link #isReady()} method for more information.
202204
*
203205
* @param readListener the {@link ReadListener} that should be notified when it's possible to read.
204206
*

api/src/main/java/jakarta/servlet/ServletOutputStream.java

+16-13
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,12 @@ public void println(double d) throws IOException {
340340
* If an attempt is made to write to the stream when the stream is in async mode and this method has not returned
341341
* {@code true} the method will throw an {@link IllegalStateException}.
342342
* <p>
343-
* If an error occurs and {@link WriteListener#onError(Throwable)} is invoked then this method will always return false,
344-
* as no further IO operations are allowed after {@code onError} notification.
345-
* <p>
346-
* Note that due to the requirement for {@code write} to never throw in async mode, this method must return false if a
347-
* call to {@code write} would result in an exception.
343+
* If an error occurs then either: this method will return {@code true} and
344+
* an {@link IOException} will be thrown from a subsequent call to {@code write(...)};
345+
* or this method will return {@code false} and subsequently {@link WriteListener#onError(Throwable)}
346+
* will be invoked with the error. Once the error has either been thrown or passed to
347+
* {@link WriteListener#onError(Throwable)}, then this method will always return {@code true} and all
348+
* further {@code write} operations will throw an {@link IOException}.
348349
*
349350
* @return {@code true} if data can be written without blocking, otherwise returns {@code false}.
350351
* @see WriteListener
@@ -356,15 +357,17 @@ public void println(double d) throws IOException {
356357
* Instructs the <code>ServletOutputStream</code> to invoke the provided {@link WriteListener} when it is possible to
357358
* write.
358359
* <p>
359-
* Note that after this method has been called methods on this stream that are documented to throw {@link IOException}
360-
* will no longer throw these exceptions directly, instead any exception that occurs will be reported via
361-
* {@link WriteListener#onError(Throwable)}. Please refer to this method for more information. This only applies to
362-
* {@code IOException}, other exception types may still be thrown (e.g. methods can throw {@link IllegalStateException}
363-
* if {@link #isReady()} has not returned true).
360+
* Note that after this method has been called, methods on this stream that are documented
361+
* to throw {@link IOException} might not throw these exceptions directly,
362+
* instead they may be reported via {@link ReadListener#onError(Throwable)} after a call to
363+
* {@link #isReady()} has returned {@code false}.
364+
* Please refer to {@link #isReady()} method for more information.
364365
* <p>
365-
* Once this method has been called {@link #flush()} and {@link #close()} become asynchronous operations, they will be
366-
* performed in the background and any problems will be reported through the {@link WriteListener#onError(Throwable)}
367-
* method.
366+
* Once this method has been called {@link #flush()} and {@link #close()} become asynchronous
367+
* operations, possibly performed in the background. Thus any problems may be reported through the
368+
* {@link WriteListener#onError(Throwable)} method, which may be called at any time
369+
* after a {@link #close()} or otherwise only after a call to {@link #isReady()} has returned
370+
* {@code false}.
368371
*
369372
* @param writeListener the {@link WriteListener} that should be notified when it's possible to write
370373
*

0 commit comments

Comments
 (0)