我在Spring Webflow中遇到了奇怪的错误。
2019-06-07 15:04:39.026 ERROR 29470 --- [nio-8096-exec-8] o.a.c.c.C.[.[.[.[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException: null
at org.springframework.webflow.execution.repository.support.AbstractFlowExecutionRepository.getConversation(AbstractFlowExecutionRepository.java:170) ~[spring-webflow-2.4.4.RELEASE.jar:2.4.4.RELEASE]
at org.springframework.webflow.execution.repository.support.AbstractFlowExecutionRepository.getLock(AbstractFlowExecutionRepository.java:125) ~[spring-webflow-2.4.4.RELEASE.jar:2.4.4.RELEASE]
at org.springframework.webflow.executor.FlowExecutorImpl.launchExecution(FlowExecutorImpl.java:142) ~[spring-webflow-2.4.4.RELEASE.jar:2.4.4.RELEASE]
at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:263) ~[spring-webflow-2.4.4.RELEASE.jar:2.4.4.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) ~[spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
这是在spring webflow库内部发生的,我完全不知道为什么。 我的流程如下:
<action-state id="checkProductAvailable">
<evaluate expression="knowledgeSourceService.test(requestParameters.productUUid, requestParameters._eventId)"/>
<transition on="internet" to="validateAndProceedToSummary">
<evaluate expression="knowledgeSourceService.extractCustomerSelectedSourceFromRequest(requestParameters)"
result="flowScope.customerSelectedSource"/>
<evaluate expression="knowledgeSourceService.enhanceProductData(requestParameters.productUUid)"
result="conversationScope.selectedProduct"/>
</transition>
<transition on="requireProducts" to="products" />
</action-state>
<decision-state id="validateAndProceedToSummary">
<if test="knowledgeSourceService.updateCustomerSelection(flowScope.customerSelectedSource, flowScope.productList.selectedProduct.customerSelectedSource)"
then="proceedToSummary" else="invalidateFormState"/>
</decision-state>
当我从validateAndProceedToSummary
切换回products
时,它可以正常运行。但是,有了这个validateAndProceedToSummary
决策状态,它就失败了。
products
处于查看状态:
<view-state id="products" view="invest-flow-products" model="productList">
你能帮我吗?
knowledgeSourceService.updateCustomerSelection(flowScope.customerSelectedSource, flowScope.productList.selectedProduct.customerSelectedSource)
是调用方法:
public boolean updateCustomerSelection(String old, String new) {
但是据我所知,它并没有达到成功路径(proceedToSummary
)的此方法(I'put Breakpoint)。它仅在执行失败路径(invalidateFormState
)时到达。因此,一些先决条件没有得到满足。但不知道哪个。我们可以以某种方式调试它吗?
答案 0 :(得分:0)
如果updateCustomerSelection()返回的是包装器布尔值,那么我们需要检查是否为null值,因为包装器布尔值也可能也包含null值。
以下代码应解决NPE问题:
if (null != updateCustomerSelection() && updateCustomerSelection()) {
//code
}
或者如果您正在使用apache commons库,则可以编写如下所示:
if (BooleanUtils.isTrue(updateCustomerSelection())) {
//code
}