我正在将Struts 1应用程序从Tomcat 6迁移到Tomcat7。大多数应用程序都工作正常,但是在提交表单时出现了以下错误。

javax.servlet.ServletException: BeanUtils.populate
    org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1254)
    org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

java.lang.NullPointerException
    org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:543)
    org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:446)
    org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:806)
    org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:884)
    org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:894)
    org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:821)
    org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:431)
    org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
    org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.55 logs.


有谁知道为什么会这样吗?

完整的堆栈跟踪为

java.lang.NullPointerException
    at org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:543)
    at org.apache.commons.beanutils.PropertyUtilsBean.getIndexedProperty(PropertyUtilsBean.java:446)
    at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:806)
    at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:884)
    at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:894)
    at org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:821)
    at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:431)
    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:646)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:610)
    at com.homedepot.ta.aa.catalina.realm.THDFormAuthenticator.invoke(Unknown Source)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at com.homedepot.ta.aa.dao.catalina.THDDAOValve.invoke(Unknown Source)
    at com.homedepot.ta.aa.catalina.realm.THDSingleSignOn.invoke(Unknown Source)
    at com.homedepot.ta.aa.catalina.valves.HDAccessLogValve.invoke(Unknown Source)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)


这甚至在进入特定类之前就已经发生。该应用程序在Tomcat 6中按预期工作。

最佳答案

我们的工作团队遇到了从Websphere 7迁移到Webshpere 8的问题。
问题是他们使用了两个使用相同名称的设置器,但使用了一个int参数,而另一个使用了Integer参数。

解决的办法是删除一个安装员。

我不确定这是否是原因,但是我认为空指针是因为集合的大小大于通过反射解决的实际方法的数量。两个具有相同名称,参数数据类型相同的设置器(本质上是因为int在通过反射获取方法时将其装箱到Integer)会在尝试迭代设置器列表时造成一次错误。

关于java - 迁移到Tomcat7后,BeanUtils.populate在struts中抛出NullPointerException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36886102/

10-10 15:16