1

这是一个奇怪的场景,我要问的是是否有人过去经历过类似的事情以及可能的情况的任何提示

我正在开发的应用程序可用于各种环境。我们通常使用 Tomcat 进行开发,我们的集成环境之一是 Websphere。

现在像这样的声明

BillingPaymentAssembler.java:149

finActivity.setReferenceNo(paymentDetail.getTicketNumber());

在哪里 ticketNumber String,在单元测试期间可以在 Tomcat 上正常运行。但是当部署在 websphere 上时,会nullPointerException为同一个测试用例抛出一个。

更新#1

我们在 UI 上使用 JSF2,paymentDetail 是 Bean。

ticket numberticketNumber是bean对应的 UI 上的一个字段。

这种情况下,当我没有在 UI 上输入任何内容时ticket number,将其留空。在那种情况下,我得到了例外

更新#2

[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R java.lang.NullPointerException
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.csa.assembler.BillingPaymentAssembler.disassemble(BillingPaymentAssembler.java:149)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.accel.AccelTransformation.disassemble(AccelTransformation.java:79)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at java.lang.reflect.Method.invoke(Method.java:600)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.ServiceHandler.invoke(ServiceHandler.java:59)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.accel.AccelService.callService(AccelService.java:1087)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.csa.process.BillingPaymentBP.process(BillingPaymentBP.java:29)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.accel.AccelBP.process(AccelBP.java:62)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at java.lang.reflect.Method.invoke(Method.java:600)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.service.ServiceControllerBP.process(ServiceControllerBP.java:54)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.service.ServiceControllerAbstract.internalExecute(ServiceControllerAbstract.java:278)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.service.ServiceControllerAbstract.execute(ServiceControllerAbstract.java:197)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.delegate.DirectServiceController.execute(DirectServiceController.java:61)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.delegate.ServiceDelegateDirect.execute(ServiceDelegateDirect.java:70)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.accel.ui.BaseServiceAction.execute(BaseServiceAction.java:584)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.accel.ui.action.policy.services.MaintainBillingPayment.perform(MaintainBillingPayment.java:145)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.accel.ui.BaseServiceAction.perform(BaseServiceAction.java:618)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.accel.ui.ServiceDelegator.execute(ServiceDelegator.java:506)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.accel.ui.ServiceDelegator.processEvent(ServiceDelegator.java:240)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.accel.ui.BeanBase.executeEvent(BeanBase.java:779)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at pagecode.policy.file.Billing.executeBillingPayments(Billing.java:498)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at java.lang.reflect.Method.invoke(Method.java:600)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at org.apache.el.parser.AstValue.invoke(AstValue.java:131)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:67)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at javax.faces.component.UICommand.broadcast(UICommand.java:315)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:775)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1267)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1655)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1595)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.csc.fs.accel.ui.filters.ResponseHeaderFilter.doFilter(ResponseHeaderFilter.java:82)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:895)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:932)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:500)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:183)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
[1/16/13 5:25:02:750 EST] 00000019 SystemErr     R  at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550)
4

1 回答 1

2

我假设这ticketNumberNumber( Integer, Long, Double, 等) 的一个实例。通常,当使用原始类型(intlongdouble等)时,EL 会自动将提交的空字符串值强制为原始类型的默认值,即0or 0.0。在包装对象类型的情况下,EL 解析器存在差异,因为EL 规范对此并不十分清楚和/或因为强制对null非原始类型上的空字符串提交值更有意义。

带有 Apache EL 解析器的 Tomcat 会将提交的空字符串Number类型值强制为原始表示的默认值。因此,类型上的空提交值Integer将被设置为0而不是null. 显然,您认为这是“正确”的行为,并且您的代码也被这样编写以拦截。

但是,其他服务器(例如本例中的 WebSphere)将强制它们null使用原始表示的默认值,而不是原始表示的默认值,从而导致 NPE。

基本上,错误在您的代码中。您应该考虑null价值,或者使用if来int代替“无价值”的有效表示(这取决于您的业务需求)。为了让所有服务器的行为都相同,您基本上还应该指示 Tomcat不要将提交的空字符串值强制到. 您可以通过将以下 VM 参数添加到 Tomcat 启动脚本来做到这一点:Integer0Number0

-Dorg.apache.el.parser.COERCE_TO_ZERO=false

请注意,这个问题本质上与 JSF 无关。它只是碰巧使用EL。

也可以看看:

于 2013-01-16T12:05:30.807 回答