Bug 35410

Summary: NullPointerException when using out scriptlet (<%= obj %>) on object with toString() returning null
Product: Tomcat 5 Reporter: Olivier Jaquemet <olivier.jaquemet>
Component: JasperAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: 5.0.30   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Olivier Jaquemet 2005-06-18 08:33:01 UTC
Here is a simple test case to reproduce the bug:

	<%!
	 class MyTestClass {
	   public String toString() {
	     return null;
	   }
	 }
	%>
	<%
	  String nullString = null;
	  MyTestClass test = new MyTestClass();
	%>
	<%= (Object) null %><%-- works well --%>
	<%= nullString %><%-- works well --%>
	<%= test %> <%-- crash --%>

this leads to:
java.lang.NullPointerException
	org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:337)
	org.apache.jasper.runtime.JspWriterImpl.print(JspWriterImpl.java:475)
	org.apache.jsp.test_jsp._jspService(test_jsp.java:65)

I consider this to be a bug cause nowhere in the behaviour of toString it is
specified it should not return null. Therefore, it should not crash like that.
Comment 1 Yoav Shapira 2005-07-22 15:01:25 UTC
Patched to prevent NPE in this case.  Thanks.
Comment 2 Konstantin Kolinko 2013-01-30 12:40:29 UTC
Reverted in Tomcat 7.0.35 by r1427821
See bug 54241 for a discussion.