Author: markt Date: Wed Jan 2 14:47:01 2013 New Revision: 1427804 URL: http://svn.apache.org/viewvc?rev=1427804&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54241 Revert the fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=35410 as it is not specification compliant Remove the remainder of the write(String) method as well as it serves no purpose since it is identical to the method it overrides. Add some test cases to confirm the expected/correct behaviour Note: BZ 35410 claims there is no requirement for Object.toString() to be non-null. Many have argued (and I agree) that null is not a String representation and therefore not a valid return value for Object.toString().
Added: tomcat/trunk/test/org/apache/jasper/runtime/TestJspWriterImpl.java tomcat/trunk/test/webapp-3.0/bug5nnnn/bug54241a.jsp tomcat/trunk/test/webapp-3.0/bug5nnnn/bug54241b.jsp Modified: tomcat/trunk/java/org/apache/jasper/runtime/JspWriterImpl.java Modified: tomcat/trunk/java/org/apache/jasper/runtime/JspWriterImpl.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/runtime/JspWriterImpl.java?rev=1427804&r1=1427803&r2=1427804&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/runtime/JspWriterImpl.java (original) +++ tomcat/trunk/java/org/apache/jasper/runtime/JspWriterImpl.java Wed Jan 2 14:47:01 2013 @@ -339,21 +339,6 @@ public class JspWriterImpl extends JspWr } } - /** - * Write a string. This method cannot be inherited from the Writer class - * because it must suppress I/O exceptions. - */ - @Override - public void write(String s) throws IOException { - // Simple fix for Bugzilla 35410 - // Calling the other write function so as to init the buffer anyways - if(s == null) { - write(s, 0, 0); - } else { - write(s, 0, s.length()); - } - } - static final String lineSeparator = System.getProperty("line.separator"); Added: tomcat/trunk/test/org/apache/jasper/runtime/TestJspWriterImpl.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/runtime/TestJspWriterImpl.java?rev=1427804&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/jasper/runtime/TestJspWriterImpl.java (added) +++ tomcat/trunk/test/org/apache/jasper/runtime/TestJspWriterImpl.java Wed Jan 2 14:47:01 2013 @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jasper.runtime; + +import java.io.File; + +import javax.servlet.http.HttpServletResponse; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.startup.TomcatBaseTest; +import org.apache.tomcat.util.buf.ByteChunk; + +public class TestJspWriterImpl extends TomcatBaseTest { + + @Test + public void bug54241a() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File appDir = new File("test/webapp-3.0"); + tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); + + tomcat.start(); + + ByteChunk res = new ByteChunk(); + + int rc = getUrl("http://localhost:" + getPort() + + "/test/bug5nnnn/bug54241a.jsp", res, null); + + Assert.assertEquals(HttpServletResponse.SC_OK, rc); + + String body = res.toString(); + Assert.assertTrue(body.contains("01: null")); + Assert.assertTrue(body.contains("02: null")); + } + + @Test + public void bug54241b() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File appDir = new File("test/webapp-3.0"); + tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); + + tomcat.start(); + + ByteChunk res = new ByteChunk(); + + int rc = getUrl("http://localhost:" + getPort() + + "/test/bug5nnnn/bug54241b.jsp", res, null); + + Assert.assertEquals(res.toString(), + HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc); + } +} Added: tomcat/trunk/test/webapp-3.0/bug5nnnn/bug54241a.jsp URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/bug5nnnn/bug54241a.jsp?rev=1427804&view=auto ============================================================================== --- tomcat/trunk/test/webapp-3.0/bug5nnnn/bug54241a.jsp (added) +++ tomcat/trunk/test/webapp-3.0/bug5nnnn/bug54241a.jsp Wed Jan 2 14:47:01 2013 @@ -0,0 +1,28 @@ +<%-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--%> +<html> + <body> + <% + String nullString = null; + %> + <!-- JspWriter.print(Object obj) is defined to print String.valueOf(obj) + which is "null" if obj is null --> + <p>01: <%= (Object) null %></p> + <!-- JspWriter.print(String) is defined to print null for a null String --> + <p>02: <%= nullString %></p> + </body> +</html> \ No newline at end of file Added: tomcat/trunk/test/webapp-3.0/bug5nnnn/bug54241b.jsp URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/bug5nnnn/bug54241b.jsp?rev=1427804&view=auto ============================================================================== --- tomcat/trunk/test/webapp-3.0/bug5nnnn/bug54241b.jsp (added) +++ tomcat/trunk/test/webapp-3.0/bug5nnnn/bug54241b.jsp Wed Jan 2 14:47:01 2013 @@ -0,0 +1,34 @@ +<%-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--%> +<%! + class Bug54241 { + public String toString() { + return null; + } + } +%> +<html> + <body> + <% + Bug54241 bug54241 = new Bug54241(); + %> + <!-- JspWriter.print(Object obj) is defined to print String.valueOf(obj) + which is obj.toString() if obj is non-null. If obj.toString is null + then this will trigger a NullPointerException --> + <p>01: <%= bug54241 %></p> + </body> +</html> \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org