You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2014/06/14 14:31:08 UTC

svn commit: r1602584 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/jasper/compiler/Generator.java test/org/apache/jasper/compiler/TestGenerator.java test/webapp-3.0/bug56581.jsp webapps/docs/changelog.xml

Author: kkolinko
Date: Sat Jun 14 12:31:07 2014
New Revision: 1602584

URL: http://svn.apache.org/r1602584
Log:
Fix http://issues.apache.org/bugzilla/show_bug.cgi?id=56581
If an error on a JSP page occurs when response has already been committed,
do not clear the buffer of JspWriter, but flush it.
It is backport of r1600899, r1602046, r1602583 from tomcat/trunk.

Added:
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug56581.jsp
      - copied unchanged from r1602581, tomcat/trunk/test/webapp/bug5nnnn/bug56581.jsp
Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/Generator.java
    tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestGenerator.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1600899,1602046,1602583

Modified: tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/Generator.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/Generator.java?rev=1602584&r1=1602583&r2=1602584&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/Generator.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/jasper/compiler/Generator.java Sat Jun 14 12:31:07 2014
@@ -3409,7 +3409,19 @@ class Generator {
         out.printil("out = _jspx_out;");
         out.printil("if (out != null && out.getBufferSize() != 0)");
         out.pushIndent();
-        out.printil("try { out.clearBuffer(); } catch (java.io.IOException e) {}");
+        out.printil("try {");
+        out.pushIndent();
+        out.printil("if (response.isCommitted()) {");
+        out.pushIndent();
+        out.printil("out.flush();");
+        out.popIndent();
+        out.printil("} else {");
+        out.pushIndent();
+        out.printil("out.clearBuffer();");
+        out.popIndent();
+        out.printil("}");
+        out.popIndent();
+        out.printil("} catch (java.io.IOException e) {}");
         out.popIndent();
         out.printil("if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);");
         out.printil("else throw new ServletException(t);");

Modified: tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestGenerator.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestGenerator.java?rev=1602584&r1=1602583&r2=1602584&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestGenerator.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestGenerator.java Sat Jun 14 12:31:07 2014
@@ -37,6 +37,7 @@ import static org.junit.Assert.assertTru
 import org.junit.Assert;
 import org.junit.Test;
 
+import org.apache.catalina.LifecycleException;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
@@ -312,4 +313,32 @@ public class TestGenerator extends Tomca
         }
 
     }
+
+    @Test
+    public void testBug56581() throws LifecycleException {
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir =
+            new File("test/webapp-3.0");
+        // app dir is relative to server home
+        tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+
+        tomcat.start();
+
+        ByteChunk res = new ByteChunk();
+        try {
+            getUrl("http://localhost:" + getPort()
+                    + "/test/bug5nnnn/bug56581.jsp", res, null);
+            Assert.fail("An IOException was expected.");
+        } catch (IOException expected) {
+            // ErrorReportValve in Tomcat 7.0.55+, 8.0.9+ flushes and aborts the
+            // connection when an unexpected error is encountered and response
+            // has already been committed. It results in an exception here:
+            // java.io.IOException: Premature EOF
+        }
+
+        String result = res.toString();
+        assertTrue(result.startsWith("0 Hello world!\n"));
+        assertTrue(result.endsWith("999 Hello world!\n"));
+    }
 }

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1602584&r1=1602583&r2=1602584&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Sat Jun 14 12:31:07 2014
@@ -154,6 +154,11 @@
         <code>Parser</code> to <code>JspReader</code> class for better
         performance. (kkolinko)
       </update>
+      <update>
+        <bug>56581</bug>: If an error on a JSP page occurs when response has
+        already been committed, do not clear the buffer of JspWriter, but flush
+        it. It will make more clear where the error occurred. (kkolinko)
+      </update>
     </changelog>
   </subsection>
   <subsection name="WebSocket">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org