-----Original Message-----
From: Geir Magnusson Jr. [mailto:[EMAIL PROTECTED]]
Sent: Monday, December 18, 2000 11:52 AM
To: [EMAIL PROTECTED]
Subject: RE: cvs commit: jakarta-velocity/src/java/org/apache/velocity Con text.javaWe 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:[EMAIL PROTECTED]]
Sent: Monday, December 18, 2000 2:40 PM
To: '[EMAIL PROTECTED]'
Subject: RE: cvs commit: jakarta-velocity/src/java/org/apache/velocity Con text.javaHey 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);
> }
>
>
>
>
>
Title: RE: cvs commit: jakarta-velocity/src/java/org/apache/velocity Con text.java
Geir,
calm down :-)
I know
context is not a Hashtable, but Context.context (the variable) is. And
Hashtable.put()
Hashtable.get() and the rest disallow the usage of NULL values. You
cannot store NULL values
in a
Hashtable. You can do that in other implementatios of the Map interface, but not
in Hashtable.
So,
since aparently the only advantage of the new code is to report a better
error message,
I
suggested you only spend checking for it, if the operation on the Hashtable
fails,
the
test for null will be done by the Hashtable methods anyway:
try
{
context.methodHere(...);
}
catch
(NullPointerException e)
{
if (first arg was null) throw ...
if (second arg was null) throw ...
// Otherwise
throw e;
}
- RE: cvs commit: jakarta-velocity/src/java/org/apach... Geir Magnusson Jr.
- Re: cvs commit: jakarta-velocity/src/java/org/... Daniel Rall
- RE: cvs commit: jakarta-velocity/src/java/org/... Jose Alberto Fernandez
- RE: cvs commit: jakarta-velocity/src/java/org/... Geir Magnusson Jr.
