Bug 5258 - nullPointerExcpetion when using getColumn
Summary: nullPointerExcpetion when using getColumn
Status: CLOSED WONTFIX
Alias: None
Product: Taglibs
Classification: Unclassified
Component: DBTags Taglib (show other bugs)
Version: 1.0B1
Hardware: PC All
: P3 blocker (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-12-04 02:28 UTC by Wim Bervoets
Modified: 2005-03-20 17:06 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wim Bervoets 2001-12-04 02:28:55 UTC
the following doesn't work:

<sql:connection id="conn1">
  <sql:url initParameter="dbURL"/> 
  <sql:driver initParameter="mysqlDriver"/>
  <sql:userId initParameter="dbUserId"/> 
  <sql:password initParameter="dbPassword"/>
</sql:connection>

<sql:statement id="stmt1" conn="conn1">
 
 	<sql:query>
    select wanted_text from wanted_bios 
    ORDER BY wanted_text
  	</sql:query>

<ul>
<sql:resultSet id="rset2">
  <li><sql:getColumn colName="wanted_text"/>

</sql:resultSet>
</ul>
</sql:statement>
<sql:closeConnection conn="conn1"/>

The error I get:

[2001/12/04 11:07:26] null
java.lang.NullPointerException
	at
org.apache.taglibs.dbtags.resultset.BaseGetterTag.getColumnNumber(BaseGetter
Tag.java:239)
	at
org.apache.taglibs.dbtags.resultset.BaseGetterTag.getPosition(BaseGetterTag.
java:111)
	at
org.apache.taglibs.dbtags.resultset.GetColumnTag.doStartTag(GetColumnTag.jav
a:116)
	at _wanted__jsp._jspService(_wanted__jsp.java:211)
	at com.caucho.jsp.JavaPage.service(JavaPage.java:74)
	at com.caucho.jsp.Page.subservice(Page.java:485)
	at
com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:176)
	at com.strangegizmo.filter.GzipFilter.doFilter(GzipFilter.java:117)
	at
com.caucho.server.http.FilterChainFilter.doFilter(FilterChainFilter.java:87)
	at com.caucho.server.http.Invocation.service(Invocation.java:278)
	at
com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:129)
	at
com.caucho.server.http.ServletServer.serviceTop(ServletServer.java:847)
	at
com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:213)
	at
com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:158)
	at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
	at java.lang.Thread.run(Thread.java:484)


It is clear that <sql:getColumn colName="wanted_text"/> is the thing that
gives me the null pointer exception. When there is only one element returned
from the database this doesn't happen, only when two or more elements are
returned. Also <sql:getColumn position="1"/> gives me the same error. 

I've been looking into the code and it happens because _name is null the
second time:

In BaseGetterTag.java:

public int getPosition() throws JspTagException{
    // if the column was set according to its name,
    // figure out its position
    System.out.println("position:" + _position);
    if (_position == -1) {
      _position = getColumnNumber(_name);
    }
    System.out.println("position after if:" + _position);
    return _position;
  }

the second time the code gets executed (second result from the db) _position
= -1 (I don't know why, when  I do getColumn position = 1 I'm not using the
column name at all

So we pass _name (a null value) to that function and in that function we do
: strName.equalsIgnoreCase (meta.getColumnName (i))

(strName == null !!!!)

Can someone from the developers tell me why _name doesn't get properly set
the second time ? Or why the _position doesn't get properly set ? (should be
1, and not -1 logically?)

I'm using Resin 2.0.4 (downloadable at http://www.caucho.com), but Resin
2.0.2 gives the same errors.

Tried DBTags beta 1 and latest nightly build from December 3rd, 2001
Comment 1 Wim Bervoets 2001-12-05 02:22:51 UTC
After talking to Resin developers we've found out it is a bug in DBTags.

The BaseGetterTag.doEndTag() violates the spec by setting _name to null. Tags 
may not change attribute values until release it called. 

More information at http://www.caucho.com/quercus/bugtrack/view.xtp?
bugreport_id=135

A proposed fix is:

In BaseGetterTag.doEndTag() :

  /**
   * If I understand the new JSP spec correctly, release()
   * is NOT called between invocations of a cached taglib,
   * so I guess we do it manually or write a new method.
   * 
   * @return EVAL_PAGE constant
   */
  public int doEndTag() {
    return EVAL_PAGE;
  }

(I removed the call to release() )

Resin 2.0.x and DBTags now work okay :-)

Wim Bervoets

Comment 2 Morgan Delagrange 2002-04-15 02:37:55 UTC
The JSP 1.1 spec was sadly vague with regard to certain aspect of the taglib 
lifecycle.  If I understand the JSP 1.2 spec correctly, release() is only 
guaranteed to be called upon garbage collection of a tag, which is not 
necessarily with every invocation.  Therefore, tags must reset their state 
manually.

My guess is that this version of Resin does not call the getter methods on a 
tag while inside a loop (either when faced with a constant, or always).  Is 
this the case?  If so, it sounds like an optimization that does not agree with 
the lifecycle clarifications in the JSP 1.2 spec.