You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Geir Magnusson Jr." <gm...@xyris.com> on 2000/12/18 20:51:58 UTC

RE: cvs commit: jakarta-velocity/src/java/org/apache/velocity Con text.java

We know.  

I personally think that Context should accept null values and keys and not
throw exceptions, but that's just me.  If you want to store a null, great.
Context will give it back when you ask for it :)

It's not a Hashtable.  It uses a Hashtable.  It acts like a hashtable.  But
it's not a hashtable.

With apologies to Senator Lloyd Benstsen :  "I know Hashtable.  I served wth
Hashtable.  Context, you are no Hashtable."

geir

> -----Original Message-----
> From:	Jose  Alberto Fernandez [SMTP:JFernandez@viquity.com]
> Sent:	Monday, December 18, 2000 2:40 PM
> To:	'velocity-dev@jakarta.apache.org'
> Subject:	RE: cvs commit:
> jakarta-velocity/src/java/org/apache/velocity Con text.java
> 
> Hey guys,
> 
> I have a problem with this commit. This change in signature of the
> context methods means that now we will have to catch exceptions all over
> the
> code.
> 
> Also, the Hashtable is already doing all this checks. It is much more
> efficient to catch the NPE and then figure out why it happened.
> Since it will hardly ever happened.
> 
> In any case, we should be throwing some RuntimeException not an
> indiscriminate Exception. We should define our own Exception class:
> 
>  class ContextException extends RuntimeException
>  {
>    ...
>  }
> 
> Jose Alberto
> 
> > -----Original Message-----
> > From: jon@locus.apache.org [mailto:jon@locus.apache.org]
> > Sent: Sunday, December 17, 2000 7:53 PM
> > To: jakarta-velocity-cvs@apache.org
> > Subject: cvs commit: jakarta-velocity/src/java/org/apache/velocity
> > Context.java
> > 
> > 
> > jon         00/12/17 19:52:34
> > 
> >   Modified:    src/java/org/apache/velocity Context.java
> >   Log:
> >   NPE checking
> >   
> >   Revision  Changes    Path
> >   1.11      +15 -1     
> > jakarta-velocity/src/java/org/apache/velocity/Context.java
> >   
> >   Index: Context.java
> >   ===================================================================
> >   RCS file: 
> > /home/cvs/jakarta-velocity/src/java/org/apache/velocity/Context.java,v
> >   retrieving revision 1.10
> >   retrieving revision 1.11
> >   diff -u -r1.10 -r1.11
> >   --- Context.java	2000/12/13 01:52:19	1.10
> >   +++ Context.java	2000/12/18 03:52:33	1.11
> >   @@ -69,7 +69,7 @@
> >     * are stored in a Hashtable. 
> >     * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
> >     * @author <a href="mailto:geirm@optonline.net">Geir 
> > Magnusson Jr.</a>
> >   - * @version $Id: Context.java,v 1.10 2000/12/13 01:52:19 
> > geirm Exp $
> >   + * @version $Id: Context.java,v 1.11 2000/12/18 03:52:33 jon Exp $
> >     */
> >    public class Context extends InternalContext implements Cloneable
> >    {
> >   @@ -93,7 +93,12 @@
> >         * @param value The corresponding value.
> >         */
> >        public void put(String key, Object value)
> >   +        throws Exception
> >        {
> >   +        if (key == null)
> >   +            throw new Exception ("Context key was null! 
> > Value was: " + value);
> >   +        else if (value == null)
> >   +            throw new Exception ("Context value was null! 
> > Key was: " + key);
> >            context.put(key, value);
> >        }
> >    
> >   @@ -104,7 +109,10 @@
> >         * @return    The value corresponding to the provided key.
> >         */
> >        public Object get(String key)
> >   +        throws Exception
> >        {
> >   +        if (key == null)
> >   +            throw new Exception ("Context key was null!");
> >            return context.get(key);
> >        }        
> >    
> >   @@ -115,7 +123,10 @@
> >         * @return    Whether the key is in the context.
> >         */
> >        public boolean containsKey(Object key)
> >   +        throws Exception
> >        {
> >   +        if (key == null)
> >   +            throw new Exception ("Context key was null!");
> >            return context.containsKey(key);
> >        }        
> >    
> >   @@ -135,7 +146,10 @@
> >         *            if unmapped.
> >         */
> >        public Object remove(Object key)
> >   +        throws Exception
> >        {
> >   +        if (key == null)
> >   +            throw new Exception ("Context key was null!");
> >            return context.remove(key);
> >        }        
> >    
> >   
> >   
> >   
> > 

Re: cvs commit: jakarta-velocity/src/java/org/apache/velocity Con text.java

Posted by Daniel Rall <dl...@finemaltcoding.com>.
"Geir Magnusson Jr." <gm...@xyris.com> writes:

> I personally think that Context should accept null values and keys and not
> throw exceptions, but that's just me.  If you want to store a null, great.
> Context will give it back when you ask for it :)
> 
> It's not a Hashtable.  It uses a Hashtable.  It acts like a hashtable.  But
> it's not a hashtable.

Null values are your friend.  I'm not sure of the value of null keys, however.

Daniel