You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Arun Sharma <ar...@escalate.com> on 2000/03/31 23:20:30 UTC

session.setAttribute semantics

The current jakarta implementation of HttpSession.setAtttribute results in
HttpSessionBindingListener.valueUnbound getting called even if the
new value is the same as the old one.

This behavior is different from some other commercial implementations of the
same API. The Servlet 2.2 spec doesn't seem to be very specific about this.

If an object is trying to use valueUnbound to clean up, it ends up cleaning 
itself up prematurely.

The attached patch against Tomcat 3.0 changes the behavior.

	-Arun

***
/home/arun/jakarta/jakarta-tomcat/src/share/org/apache/tomcat/core/Applicati
onSession.java-
---
/home/arun/jakarta/jakarta-tomcat/src/share/org/apache/tomcat/core/Applicati
onSession.java

***************
*** 222,228 ****
  	    throw new IllegalArgumentException(msg);
  	}
  
! 	removeValue(name);  // remove any existing binding
  
  	if (value != null && value instanceof HttpSessionBindingListener) {
  	    HttpSessionBindingEvent e =
--- 222,237 ----
  	    throw new IllegalArgumentException(msg);
  	}
  
! 	Object o = values.get(name);
!     if (o != value) {
!         if (o instanceof HttpSessionBindingListener) {
!             HttpSessionBindingEvent e =
!                 new HttpSessionBindingEvent(this,name);
!             
!             ((HttpSessionBindingListener)o).valueUnbound(e);
!         }
!     }
!     values.remove(name);
  
  	if (value != null && value instanceof HttpSessionBindingListener) {
  	    HttpSessionBindingEvent e =