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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, December 17, 2000 7:53 PM
> To: [EMAIL PROTECTED]
> 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:[EMAIL PROTECTED]">Jason van Zyl</a>
>     * @author <a href="mailto:[EMAIL PROTECTED]">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);
>        }        
>    
>   
>   
>   
> 

Reply via email to