velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Esposito" <espos...@newnetco.com>
Subject NullPointerException for undefined member of hashtable
Date Thu, 15 Mar 2001 14:48:53 GMT
I'm wondering if this is normal behavior ... I have the following situation
(a little bit pseudocoded)

public class MetaDataObject
{
	public MetaDataObject(String a)
	{fName = a;}

	public String fName;

	public String getFirstName()
	{ return fName;}
}

Hashtable metaData = new Hashtable()

metaData.put("Programmer",new MetaDataObject("Dave"));
metaData.put("Administrator",new MetaDataObject("Bob"));
metaData.put("Secretary",new MetaDataObject("Jane"));

ctx.put("metaData",metaData);

in my VTL i do

$!metaData.Programmer.FirstName

$!metaData.Administrator.FirstName

$!metaData.Secretary.FirstName

$!metaData.Billing.FirstName


But since Billing is not in the Hashtable, Velocity throws a NPE and dumps
the stack to the console ... It would be nice if it just caught this
exception and maybe just logged it to the log file or something?

Example:

 java.lang.NullPointerException
        at org.apache.velocity.runtime.parser.node.ASTIdentifier
.execute(ASTIdentifier.java:159)
        at org.apache.velocity.runtime.parser.node.ASTReference.
execute(ASTReference.java:159)
        at org.apache.velocity.runtime.parser.node.ASTReference.
render(ASTReference.java:174)
        at org.apache.velocity.runtime.parser.node.SimpleNode.re
nder(SimpleNode.java:255)
        at org.apache.velocity.Template.merge(Template.java:281)

        at org.apache.velocity.servlet.VelocityServlet.mergeTemp
late(VelocityServlet.java:313)
        at org.apache.velocity.servlet.VelocityServlet.doRequest
(VelocityServlet.java:258)
        at org.apache.velocity.servlet.VelocityServlet.doPost(Ve
locityServlet.java:213)
        at javax.servlet.http.HttpServlet.service(HttpServlet.ja
va:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.ja
va:853)
        at org.apache.tomcat.core.ServletWrapper.doService(Servl
etWrapper.java:404)
        at org.apache.tomcat.core.Handler.service(Handler.java:2
86)
        at org.apache.tomcat.core.ServletWrapper.service(Servlet
Wrapper.java:372)
        at org.apache.tomcat.core.ContextManager.internalService
(ContextManager.java:797)
        at org.apache.tomcat.core.ContextManager.service(Context
Manager.java:743)
        at org.apache.tomcat.service.http.HttpConnectionHandler.
processConnection(HttpConnectionHandler.java:210)
        at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolT
cpEndpoint.java:416)
        at org.apache.tomcat.util.ThreadPool$ControlRunnable.run
(ThreadPool.java:498)
        at java.lang.Thread.run(Unknown Source)
 ASTIdentifier.execute() : identifier = MaxLength : java.lang.Nu
llPointerException


Mime
View raw message