jakartaee / jakartaee/servlet

Clarify how async ReadListener changes the contract of ServletInputStream methods

Open
#301 6 comments 0 reactions 0 assignees View on GitHub
Candidate4NextRelease
Dominant language
Java
Stars
325
Forks
112
PR merge metrics
No merged PRs in 30d

Description

The use of an async `ReadListener` allows the normal read methods to be used in async mode. However nowhere in the javadoc do we document how that behaviour is changed and I think they may be a few corner cases that are ambiguous:

+ can the `ServletInputStream.readLine` method be used? Currently it has a default implementation that will fail in async mode as `isReady()` is not called. Should implementations override this with a method that works asynchronously and returns 0 if a complete line is not available? Or should the default implementation be updated to throw ISE if there is a ReadListener?
+ Ditto for `readAllBytes()` and `readNBytes(...)`, `skip(long)`, `skipNBytes(long)`, `transferTo(OutputStream)`: should they ISE, block or return null if insufficient data is available?
+ The javadoc of `isReady()` is very light on and really needs to make clear the scheduling implications of a false return - ie that one of the `ReadListener` callbacks will eventually be called if false is return.
+ If `read(byte[],int,int)` is called without previously calling `isReady()`:
* Should ISE always be thrown?
* Should ISE be thrown only if there is no data available?
* Should 0 be returned if there is no data available? If so, is this equivalent to a call to `isReady()` returning false? ie will a callback be scheduled when data is available?
+ If `read(byte[],int,int)` is called after `isReady()` returns false and `onDataAvailable`, should 0 be returned or ISE thrown?
+ If `read()` is called, then returning 0 is not an option as it is a valid byte. So how should `read()` handle all of the situations above?

Contributor guide

Open the contributing guide

Research direction

Start with the ServletInputStream and ReadListener entry points, then review the existing Javadoc for readLine(), readAllBytes(), readNBytes(), skip(), skipNBytes(), transferTo(), isReady(), and read methods. Determine the intended async contract for each case and document the agreed behavior, including callback scheduling and exception or return-value rules.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.