setAttribute behaviour when passing null as attribute

2001-05-30 Thread Thomas Krebs

Hope, this wasn't discussed already (I browsed through the list but didn't
find it), if it was I apologize.

What is the expected result of calling setAttribute on an instance of
ServletRequest, if the attribute to be passed is null (i.e.
request.setAttribute(someName, null))?
I would expect that for the given name null is stored which would ensure
that a getAttribute call afterwards would return null as well.
However, the Tomcat implementation will leave the value unchanged:

--- code snippet from RequestImpl ---
Class org.apache.tomcat.core.RequestImpl.java line 614

public void setAttribute(String name, Object value) {
 if(name!=null  value!=null)
 attributes.put(name, value);
}

--- end code snippet

Since other servlet container behave differently at least JRun does, namely
 setting it to null, I wonder whether this is a bug in Tomcat?
I would argue that the expected behaviour is that getAttribute(name)
returns null, if  a value for name was never set. In all other cases,
it should return exactly the value set with the last setAttribute call.

Any opinions on that?

best regards,
thomas





Re: setAttribute behaviour when passing null as attribute

2001-05-30 Thread anil

I do not think this is posiible.  Session attributes are stored in a hashtable.
You cannot save null value to hashtable.

If you try session.setAttribute(myValue,null);
you will get null pointer exception with error 500.

I might have missed some thing, but take a look at  package
org.apache.tomcat.session.

anil

Thomas Krebs wrote:

 Hope, this wasn't discussed already (I browsed through the list but didn't
 find it), if it was I apologize.

 What is the expected result of calling setAttribute on an instance of
 ServletRequest, if the attribute to be passed is null (i.e.
 request.setAttribute(someName, null))?
 I would expect that for the given name null is stored which would ensure
 that a getAttribute call afterwards would return null as well.
 However, the Tomcat implementation will leave the value unchanged:

 --- code snippet from RequestImpl ---
 Class org.apache.tomcat.core.RequestImpl.java line 614

 public void setAttribute(String name, Object value) {
  if(name!=null  value!=null)
  attributes.put(name, value);
 }

 --- end code snippet

 Since other servlet container behave differently at least JRun does, namely
  setting it to null, I wonder whether this is a bug in Tomcat?
 I would argue that the expected behaviour is that getAttribute(name)
 returns null, if  a value for name was never set. In all other cases,
 it should return exactly the value set with the last setAttribute call.

 Any opinions on that?

 best regards,
 thomas