This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit aceb64d504f1adcb49319acf1973c3262b49048a Author: Mark Thomas <ma...@apache.org> AuthorDate: Mon Dec 6 22:44:11 2021 +0000 Use specialised exception for the case of ByteChunk overflow This enables the option of specific handling for this case further up the stack --- java/org/apache/tomcat/util/buf/ByteChunk.java | 17 ++++++++++++++++- java/org/apache/tomcat/util/buf/LocalStrings.properties | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/java/org/apache/tomcat/util/buf/ByteChunk.java b/java/org/apache/tomcat/util/buf/ByteChunk.java index 3ba68af..748e101 100644 --- a/java/org/apache/tomcat/util/buf/ByteChunk.java +++ b/java/org/apache/tomcat/util/buf/ByteChunk.java @@ -24,6 +24,8 @@ import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import org.apache.tomcat.util.res.StringManager; + /* * In a server it is very important to be able to operate on * the original byte[] without converting everything to chars. @@ -118,6 +120,8 @@ public final class ByteChunk extends AbstractChunk { // -------------------- + private static final StringManager sm = StringManager.getManager(ByteChunk.class); + /** * Default encoding used to convert to strings. It should be UTF8, as most * standards seem to converge, but the servlet API requires 8859_1, and this @@ -466,7 +470,8 @@ public final class ByteChunk extends AbstractChunk { public void flushBuffer() throws IOException { // assert out!=null if (out == null) { - throw new IOException("Buffer overflow, no sink " + getLimit() + " " + buff.length); + throw new BufferOverflowException(sm.getString("byteChunk.noSink", + Integer.valueOf(getLimit()), Integer.valueOf(buff.length))); } out.realWriteBytes(buff, start, end - start); end = start; @@ -830,4 +835,14 @@ public final class ByteChunk extends AbstractChunk { } return result; } + + + public static class BufferOverflowException extends IOException { + + private static final long serialVersionUID = 1L; + + public BufferOverflowException(String message) { + super(message); + } + } } diff --git a/java/org/apache/tomcat/util/buf/LocalStrings.properties b/java/org/apache/tomcat/util/buf/LocalStrings.properties index fb860d7..8440c7f 100644 --- a/java/org/apache/tomcat/util/buf/LocalStrings.properties +++ b/java/org/apache/tomcat/util/buf/LocalStrings.properties @@ -20,6 +20,8 @@ b2cConverter.unknownEncoding=The character encoding [{0}] is not supported byteBufferUtils.cleaner=Cannot use direct ByteBuffer cleaner, memory leaking may occur +byteChunk.noSink=Cannot write [{1}] bytes to ByteChunk with limit [{0}] as it has no sink for overflow + c2bConverter.recycleFailed=Failed to recycle the C2B Converter. Creating new BufferedWriter, WriteConvertor and IntermediateOutputStream. encodedSolidusHandling.invalid=The value [{0}] is not recognised --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org