Skip to content

Commit

Permalink
Fix exception when getting writer with invalid charset
Browse files Browse the repository at this point in the history
Signed-off-by: Arjan Tijms <arjan.tijms@gmail.com>
  • Loading branch information
arjantijms committed Apr 7, 2022
1 parent c781be7 commit 76a7d62
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.UnsupportedCharsetException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
Expand Down Expand Up @@ -138,12 +140,20 @@ public ServletOutputStream getOutputStream() throws IOException {
public PrintWriter getWriter() throws IOException {
checkResponseNull();

PrintWriter writer = response.getWriter();
if (isFinished()) {
response.setSuspended(true);
}
try {
PrintWriter writer = response.getWriter();
if (isFinished()) {
response.setSuspended(true);
}

return writer;
return writer;
} catch (UnsupportedCharsetException e) {
// Servlet 6 states we should throw an UnsupportedEncodingException, but our backend
// naturally throws an UnsupportedCharsetException.
UnsupportedEncodingException unsupportedEncodingException = new UnsupportedEncodingException();
unsupportedEncodingException.initCause(e);
throw unsupportedEncodingException;
}
}

@Override
Expand Down

0 comments on commit 76a7d62

Please sign in to comment.