Skip to content

Commit

Permalink
ErrorContent must not hold a null exception
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
  • Loading branch information
lorban committed Jun 7, 2022
1 parent b199c71 commit 6baf0c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Expand Up @@ -31,7 +31,7 @@
class AsyncContentProducer implements ContentProducer
{
private static final Logger LOG = LoggerFactory.getLogger(AsyncContentProducer.class);
private static final HttpInput.ErrorContent RECYCLED_ERROR_CONTENT = new HttpInput.ErrorContent(new IllegalStateException("ContentProducer has been recycled"));
private static final HttpInput.ErrorContent SENTINEL_ERROR_CONTENT = new HttpInput.ErrorContent(null);

private final AutoLock _lock = new AutoLock();
private final HttpChannel _httpChannel;
Expand Down Expand Up @@ -63,12 +63,12 @@ public void recycle()
// Make sure that the content has been fully consumed before destroying the interceptor and also make sure
// that asking this instance for content between recycle and reopen will only produce error'ed content.
if (_rawContent == null)
_rawContent = RECYCLED_ERROR_CONTENT;
_rawContent = SENTINEL_ERROR_CONTENT;
else if (!_rawContent.isSpecial())
throw new IllegalStateException("ContentProducer with unconsumed content cannot be recycled");

if (_transformedContent == null)
_transformedContent = RECYCLED_ERROR_CONTENT;
_transformedContent = SENTINEL_ERROR_CONTENT;
else if (!_transformedContent.isSpecial())
throw new IllegalStateException("ContentProducer with unconsumed content cannot be recycled");

Expand Down Expand Up @@ -226,9 +226,13 @@ private void failCurrentContent(Throwable x)
_rawContent = null;
}

HttpInput.ErrorContent errorContent = new HttpInput.ErrorContent(x);
_transformedContent = errorContent;
_rawContent = errorContent;
HttpInput.Content finalContent;
if (x != null)
finalContent = new HttpInput.ErrorContent(x);
else
finalContent = SENTINEL_ERROR_CONTENT;
_transformedContent = finalContent;
_rawContent = finalContent;
}

@Override
Expand Down
Expand Up @@ -297,10 +297,11 @@ private int read(ByteBuffer buffer, byte[] b, int off, int len) throws IOExcepti
return read;
}

boolean isError = content instanceof ErrorContent;
Throwable error = content.getError();
if (LOG.isDebugEnabled())
LOG.debug("read error={} {}", error, this);
if (error != null)
LOG.debug("read isError={} error={} {}", isError, error, this);
if (isError)
{
if (error instanceof IOException)
throw (IOException)error;
Expand Down

0 comments on commit 6baf0c1

Please sign in to comment.