Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0.6
-
None
-
Windows 2000. J2re1.4.2. Tomcat 5.5.20.
-
Patch
Description
ScopeInterceptor uses a NULL object to store null values in session scope.
When restarting tomcat, sessions are serialized on hard drive, and they are reloaded. NULL object is also serialized. But as struts2 application starts, when ScopeInterceptor class is loaded, it creates a new static field "NULL" that is not the same reference as the serialised one.
As a result, when test "o==NULL" is performed in method nullConvert, it return false, whereas it should return true. Then, fields in action that should remain to "null" value, are initialized with a "NULL" string !
To resolve this issue, introduce a new NULLClass, and check if object o extends this class, instead of testing reference equality. Use the following code as a replacement:
private static class NULLClass implements Serializable {
public String toString()
public boolean equals(Object obj)
{ return obj == null || (obj instanceof NULLClass); } }
private static final Object NULL = new NULLClass();
private static final Object nullConvert(Object o) {
if (o == null)
if (o == NULL || NULL.equals(o))
{ return null; } return o;
}
Struts 2 is a great job ! Thanks.