Skip to content

Commit

Permalink
UNDERTOW-1140 make sure read() throws an exception if isReady() has n…
Browse files Browse the repository at this point in the history
…ot been called
  • Loading branch information
stuartwdouglas committed Jul 21, 2017
1 parent 2042bdc commit ccf7abf
Showing 1 changed file with 6 additions and 1 deletion.
Expand Up @@ -61,6 +61,7 @@ public class ServletInputStreamImpl extends ServletInputStream {
private static final int FLAG_ON_DATA_READ_CALLED = 1 << 3;
private static final int FLAG_CALL_ON_ALL_DATA_READ = 1 << 4;
private static final int FLAG_BEING_INVOKED_IN_IO_THREAD = 1 << 5;
private static final int FLAG_IS_READY_CALLED = 1 << 6;

private volatile int state;
private volatile AsyncContextImpl asyncContext;
Expand Down Expand Up @@ -99,6 +100,9 @@ public boolean isReady() {
if(!ready && listener != null && !finished) {
channel.resumeReads();
}
if(ready) {
state |= FLAG_IS_READY_CALLED;
}
return ready;
}

Expand Down Expand Up @@ -153,9 +157,10 @@ public int read(final byte[] b, final int off, final int len) throws IOException
throw UndertowServletMessages.MESSAGES.streamIsClosed();
}
if (listener != null) {
if (anyAreClear(state, FLAG_READY)) {
if (anyAreClear(state, FLAG_READY | FLAG_IS_READY_CALLED) ) {
throw UndertowServletMessages.MESSAGES.streamNotReady();
}
state &= ~FLAG_IS_READY_CALLED;
} else {
readIntoBuffer();
}
Expand Down

0 comments on commit ccf7abf

Please sign in to comment.