Search code examples
javaservletsjpawebsphereequality

WebSphere equality check failure


WebSphere prints

8/7/13 11:43:47.318 000000AB SystemOut DETAIL receipt is null? = null

8/7/13 11:43:47.318 000000AB SystemOut DETAIL false

8/7/13 11:43:47.318 000000AB com.ibm.ws.webcontainer.servlet.ServletWrapper SEVERE com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet [ReceiptReportServlet] in application [MyWar_war]. Exception created : [java.lang.NullPointerException at servlet.ReceiptReportServlet.doGet(ReceiptReportServlet.java:61) at javax.servlet.http.HttpServlet.service(HttpServlet.java:575) at javax.servlet.http.HttpServlet.service(HttpServlet.java:668) at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1227) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:776) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:458) at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178) at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1032) at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87) at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:909) at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662) at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:459) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:526) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:312) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:283) at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214) at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113) at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175) at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204) at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775) at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1862) ]

instead of

receipt is null? = null

true


Solution

  • This looks more like a problem with order of operations rather than WAS. Your line that prints

    System.out.println("receipt is null? " + receipt == null);
    

    is the problem. This does not print true or false if the receipt object is null or not. What it does is concatenates the string "receipt is null? " with the result of receipt's .toString() method and THEN checks if that is equal to null. That's why you see it only print false on that line.

    If you really want to check for a null object there, add some appropriate ()'s around your null check.

    System.out.println("receipt is null? " + (receipt == null));
    

    This should print true or false as you are expecting.

    As for why the receipt is null in one environment but not null in the other is question that we don't have enough information to answer. Your code snippets don't show us where that object is coming from or is instantiated.