Bug 35410 - NullPointerException when using out scriptlet (<%= obj %>) on object with toString() returning null
NullPointerException when using out scriptlet (<%= obj %>) on object with toS...
Status: RESOLVED FIXED
Product: Tomcat 5
Classification: Unclassified
Component: Jasper
5.0.30
All All
: P3 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2005-06-18 08:33 UTC by Olivier Jaquemet
Modified: 2013-01-30 12:40 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.