Sitelet https://github.com/qos-ch/logback-access/pull/29
Skip to content

Propagate IO exceptions in TeeServletInputStream - #29

Open
ILadis wants to merge 1 commit into
qos-ch:mainfrom
ILadis:main
Open

ILadis wants to merge 1 commit into
qos-ch:mainfrom
ILadis:main

Conversation

@ILadis

@ILadis ILadis commented Nov 7, 2025 •

Copy link
Copy Markdown

When the TeeFilter is configured as described in Capturing incoming HTTP requests and outgoing responses any IO exceptions which may occur while reading the HTTP request body are not propagated (see TeeServletInputStream):

private void duplicateInputStream(HttpServletRequest request) {
    ServletInputStream originalSIS = null;
    try {
        originalSIS = request.getInputStream();
        inputBuffer = consumeBufferAndReturnAsByteArray(originalSIS);
        this.in = new ByteArrayInputStream(inputBuffer);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        closeStream(originalSIS);
    }
}

All IO exceptions are caught and the exception stack trace gets printed to the console. In this case this.in never gets assigned a value / is still set to null.

If a servlet later tries to read from the ServletInputStream a NullPointerException is thrown instead:

Caused by: java.lang.NullPointerException: Cannot invoke "java.io.InputStream.read()" because "this.in" is null
    at ch.qos.logback.access.common.servlet.TeeServletInputStream.read(TeeServletInputStream.java:49)
    ...

My change propagates the IO exception to the caller when a servlet attempts to read from the stream.

Please let me know your thoughts on these changes or if you have any suggestions for improvements.

Signed-off-by: Michael Wagner <mwagn4@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant