Source:
<code>public void readIntoAWCFailureTest() throws Exception { String errMsg = "@@ExpectedExceptionMessage@@"; InputStream stream = new ByteBufferInputStream(ByteBuffer.allocate(1)); InputStreamReadableStreamChannel channel = new InputStreamReadableStreamChannel(stream, EXECUTOR_SERVICE); ReadIntoCallback callback = new ReadIntoCallback(); try { channel.readInto(new BadAsyncWritableChannel(new IOException(errMsg)), callback).get(); fail("Should have failed because BadAsyncWritableChannel would have thrown exception"); } catch (ExecutionException e) { Exception exception = (Exception) Utils.getRootCause(e); assertEquals("Exception message does not match expected (future)", errMsg, exception.getMessage()); callback.awaitCallback(); assertEquals("Exception message does not match expected (callback)", errMsg, callback.exception.getMessage()); } channel = new InputStreamReadableStreamChannel(stream, EXECUTOR_SERVICE); channel.close(); <START> CopyingAsyncWritableChannel writeChannel = new CopyingAsyncWritableChannel(Integer.MAX_VALUE); <END> callback = new ReadIntoCallback(); try { channel.readInto(writeChannel, callback).get(); fail("InputStreamReadableStreamChannel has been closed, so read should have thrown ClosedChannelException"); } catch (ExecutionException e) { Exception exception = (Exception) Utils.getRootCause(e); assertTrue("Exception is not ClosedChannelException", exception instanceof ClosedChannelException); callback.awaitCallback(); assertEquals("Exceptions of callback and future differ", exception.getMessage(), callback.exception.getMessage()); } channel = new InputStreamReadableStreamChannel(stream, EXECUTOR_SERVICE); writeChannel = new CopyingAsyncWritableChannel(Integer.MAX_VALUE); channel.readInto(writeChannel, null); try { channel.readInto(writeChannel, null); fail("Should have failed because readInto cannot be called more than once"); } catch (IllegalStateException e) { } }</code><technical_language>Long.MAX_VALUE exact size. (We a bug caused inputting Interger.MAX_VALUE function argument expects long.)</technical_language>

Target:
public void readIntoAWCFailureTest() throws Exception { String errMsg = "@@ExpectedExceptionMessage@@"; InputStream stream = new ByteBufferInputStream(ByteBuffer.allocate(1)); InputStreamReadableStreamChannel channel = new InputStreamReadableStreamChannel(stream, EXECUTOR_SERVICE); ReadIntoCallback callback = new ReadIntoCallback(); try { channel.readInto(new BadAsyncWritableChannel(new IOException(errMsg)), callback).get(); fail("Should have failed because BadAsyncWritableChannel would have thrown exception"); } catch (ExecutionException e) { Exception exception = (Exception) Utils.getRootCause(e); assertEquals("Exception message does not match expected (future)", errMsg, exception.getMessage()); callback.awaitCallback(); assertEquals("Exception message does not match expected (callback)", errMsg, callback.exception.getMessage()); } channel = new InputStreamReadableStreamChannel(stream, EXECUTOR_SERVICE); channel.close(); CopyingAsyncWritableChannel writeChannel = new CopyingAsyncWritableChannel(); callback = new ReadIntoCallback(); try { channel.readInto(writeChannel, callback).get(); fail("InputStreamReadableStreamChannel has been closed, so read should have thrown ClosedChannelException"); } catch (ExecutionException e) { Exception exception = (Exception) Utils.getRootCause(e); assertTrue("Exception is not ClosedChannelException", exception instanceof ClosedChannelException); callback.awaitCallback(); assertEquals("Exceptions of callback and future differ", exception.getMessage(), callback.exception.getMessage()); } channel = new InputStreamReadableStreamChannel(stream, EXECUTOR_SERVICE); writeChannel = new CopyingAsyncWritableChannel(); channel.readInto(writeChannel, null); try { channel.readInto(writeChannel, null); fail("Should have failed because readInto cannot be called more than once"); } catch (IllegalStateException e) { } }