Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-1803

ScopeIntercaptor null references on session serialization

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.6
    • 2.0.7, 2.1.0
    • Core Interceptors
    • 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()

      { return "NULL"; }

      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)

      { return NULL; }

      if (o == NULL || NULL.equals(o))

      { return null; }

      return o;
      }

      Struts 2 is a great job ! Thanks.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            sribeyron Sylvain RIBEYRON
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment