tags:

views:

311

answers:

1

What would the possible scenarios be in which I would get this error produced from a struts web app?

java.lang.IllegalArgumentException: No bean specified
at org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptor(PropertyUtils.java:837)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:934)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:223)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3245)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2003)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1909)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1359)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)

Edit: I have added the stack trace above.

A: 

This is most likely thrown by the org.apache.commons.beanutils.PropertyUtils class trying to access properties from a bean which is null. Your ActionForm might be that bean.

Do you have an ActionForm defined for your Action? Check your struts-config.xml file and see if the name attribute of the <action> tag references a <form-bean>.

You are not providing enough information here, so I can only guess. You should post the stacktrace too.

EDIT: There is one other thing you could check for. From the stacktrace it seems your Action form is OK (I don't think you would have gotten so deep in the call if the form was null) but it might be something on the form.

Are you using nested properties or setting something on a bean on the form, a case like :

public class MyAction extends ActionForm {
  private SomeBean innerBean;
  ...
  public SomeBean getInnerBean() { 
    return this.innerBean; 
  }
}

If in your JSP you specified form.innerBean.someProperty when you submit a value for this, Struts will try to do something like a form.getInnerBean().setSomeProperty(...). If the part form.getInnerBean() is null, Struts will complain before you get NullPointerException.

A solution for this kind of things is to change:

public class MyAction extends ActionForm {
  private SomeBean innerBean;
  ...
}

to

public class MyAction extends ActionForm {
  private SomeBean innerBean = new SomeBean();
  ...
}

Might this be the cause?

dpb
Thanks dpb. I have added the stacktrace and will investigate further.
Ruepen
@Ruepen: see edited answer
dpb
@Ruepen: did you succeed in finding out what caused the exception?
dpb
@dpb: I have confirmed that all Actions have a corresponding ActionForm in the struts-config.xml.I did find a couple of instances where the code I am working on has nested properties as in the above example you provided. I will go ahead and make the changes you suggested, but how would I go about confirming that this will work? (Aside from seeing if the error comes up again or not). I am working on some legacy code (pre 2004) and the only logging that exists is the log4j that I just implemented in a few places. Thanks for your input, it is appreciated.
Ruepen
You should concentrate on one action form. You get the above exception when you submit your form to the server, so you have to find out where the POST is delegated. Use Mozilla's Tamper Data add-on and intercept the form submit. Based on the intercepted info, look in struts-config and find out what is the target action class and also what action form it has attached. That will be the form Struts tries to populate and that is what fails. Add logging to all getters and setters in the action form and run your app. See what is the last thing logged before the crash. That will be your culprit.
dpb
One other thing, if you added log4j to the application you could activate the loggers of Struts and common bean-utils in DEBUG level. You will have a lot of stuff written to the logs but it might provide you with useful information.
dpb