I may have found a problem using Struts/StrutsTestCase with OC4J(9.0.4).

Background: I'm running a StrutsTestCase that works in Resin 2.x but when ran in OC4J I get a NullPointerException from org.apache.struts.util.RequestUtils.java line 1806. The problem I found with both the RequestUtils.java and CactusStrutsTestCase.java are illustrated below.

The problem can be found in two places. The first is in CactusStrutsTestCase.java line 417:
String moduleName = (String) request.getAttribute(Common.INCLUDE_SERVLET_PATH);
if (moduleName.endsWith("/"))
moduleName = moduleName.substring(0,moduleName.lastIndexOf("/"));


In resin 2.X this runs correctly with moduleName being initialized to "" even if the attribute is not found.
In oc4j 9.0.4 request.getAttribute returns "null" when an attribute is not found. When moduleName.endsWith gets executed a NullPointerException is thrown.


The second is in org.apache.struts.util.RequestUtils.java introduced in line 1783 blows up on line 1806:
On line 1783 (same fundamental problem as the first error):
String matchPath = (String) request.getAttribute(RequestProcessor.INCLUDE_SERVLET_PATH);
// matchPath is set to "" in resin matchPath is null in oc4j
if (matchPath == null) {
matchPath = request.getServletPath();
}
return getModuleName( matchPath, context);


Both calls to request.getXXX return an empty string in resin. In oc4j null is returned.
The error is surfaced on line 1806:
while (prefix.equals("") && ((lastSlash = matchPath.lastIndexOf("/")) > 0)) {


Since the call to getModuleName passes in null, matchPath.lastIndexOf throws a NullPointerException.

Good news is that this is open-source and I can hack the code for myself =). I'm curious of all the other sections of code in struts that make the assumption that the request object will return an instantiated object and not "null".? It appears that the servlet 2.3 specification specifies that returning null is the correct servlet implementation.
http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletRequest.html#getAttribute(java.lang.String)


What is the best way to file bugs for both struts and strutstestcase?

Thanks in advance!

-Mark

Reply via email to