Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=46354
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 9 Apr 2009 15:11:46 +0000 (15:11 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 9 Apr 2009 15:11:46 +0000 (15:11 +0000)
ArrayIndexOutOfBoundsException when using org.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true
Pathc provided by Konstantin Kolinko

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@763681 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/jasper/runtime/BodyContentImpl.java

index 2a3a48f..1c2a8e7 100644 (file)
@@ -51,9 +51,6 @@ public class BodyContentImpl extends BodyContent {
     // Enclosed writer to which any output is written
     private Writer writer;
     
-    // See comment in setWriter()
-    private int bufferSizeSave;
-    
     /**
      * Constructor.
      */
@@ -508,6 +505,19 @@ public class BodyContentImpl extends BodyContent {
     }
     
     /**
+     * This method returns the size of the buffer used by the JspWriter.
+     *
+     * @return the size of the buffer in bytes, or 0 is unbuffered.
+     */
+    public int getBufferSize() {
+        // According to the spec, the JspWriter returned by 
+        // JspContext.pushBody(java.io.Writer writer) must behave as
+        // though it were unbuffered. This means that its getBufferSize()
+        // must always return 0.
+        return (writer == null) ? bufferSize : 0;
+    }
+    
+    /**
      * @return the number of bytes unused in the buffer
      */
     public int getRemaining() {
@@ -558,22 +568,7 @@ public class BodyContentImpl extends BodyContent {
     void setWriter(Writer writer) {
         this.writer = writer;
         closed = false;
-        if (writer != null) {
-            // According to the spec, the JspWriter returned by 
-            // JspContext.pushBody(java.io.Writer writer) must behave as
-            // though it were unbuffered. This means that its getBufferSize()
-            // must always return 0. The implementation of
-            // JspWriter.getBufferSize() returns the value of JspWriter's
-            // 'bufferSize' field, which is inherited by this class. 
-            // Therefore, we simply save the current 'bufferSize' (so we can 
-            // later restore it should this BodyContentImpl ever be reused by
-            // a call to PageContext.pushBody()) before setting it to 0.
-            if (bufferSize != 0) {
-                bufferSizeSave = bufferSize;
-                bufferSize = 0;
-            }
-        } else {
-            bufferSize = bufferSizeSave;
+        if (writer == null) {
             clearBody();
         }
     }