Menu

#46 servletContext().setAttribute(name, null) throws NPE in wl51

v1.0 (example)
closed-fixed
nobody
None
5
2004-06-08
2003-11-26
Anonymous
No

There exists a problem with strutstest and weblogic 5.1

Every time, I start a test, a null pointer is thrown.
The trace suggests, that the NPE happens, when Weblogic
sets a null-reference into the ServletContext which is
mapped internally as a HashTable. (See attached file)

A HashTable does not allow a null-reference as value in
the set-method, so that is why the excpetion is thrown
from the hashtable implementation.

This is frustrating, because the javadoc of
ServletContext clearly states that the usage of
setAttribute("key", null) is identical to the method
removeAttribute( "key" ), but due to internals of wl
5.1, it does not work this way.

My workaround:
I changed two lines in the method getActionServlet
(line 410+421) of CactusStrutsTestCase from
410> config.getServletContext().setAttribute(name, null);
421> config.getServletContext().setAttribute(name +
moduleName, null);

to
410> config.getServletContext().removeAttribute(name);
421> config.getServletContext().removeAttribute(name +
moduleName);

and everthing works fine with wl51.

I noticed this problem with strutstest2.0

I would highly appreciate it, if the patch could become
part of strutstest. Everyone who still uses weblogic
5.1 will be gratefull.

Discussion

  • Nobody/Anonymous

    exception trace

     
  • Nobody/Anonymous

    Logged In: NO

    This bug also exists in WLS8.1 and strutstest-2.1.0.
    The workaround solves the problem.

    anders.janmyr@jayway.se

     
  • Deryl Seale

    Deryl Seale - 2004-06-08

    Logged In: YES
    user_id=366284

    Fixed in latest release.

     
  • Deryl Seale

    Deryl Seale - 2004-06-08
    • status: open --> closed-fixed
     

Log in to post a comment.