Search code examples
javawebsphereraddom4j

Nullpointer exception with dom4j on Websphere


I use RAD and websphere to develop a J2EE app and when I try to execute this code from DOM4J library:

XPath xpathSelector = DocumentHelper.createXPath("//annee[@annee='"+request.getAnnee()+ "']/offre[@nomOffre='"+request.getOffre()+"'"+conditionProfile+"]/produit[@nomProduit='"+request.getProduit()+"']/"+request.getTypeDocument() +"/specificite[@type='"+request.getSpecificite()+"']/*");
List nodes = xpathSelector.selectNodes(doc);

doc is a org.dom4j.Document object.

I get the following error:

java.lang.NullPointerException
at org.jaxen.util.DescendantAxisIterator.hasNext(DescendantAxisIterator.java:101)
at org.jaxen.expr.DefaultStep.evaluate(DefaultStep.java:152)
at org.jaxen.expr.DefaultLocationPath.evaluate(DefaultLocationPath.java:140)
at org.jaxen.expr.DefaultAbsoluteLocationPath.evaluate(DefaultAbsoluteLocationPath.java:113)
at org.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:102)
at org.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:674)
at org.jaxen.BaseXPath.selectNodes(BaseXPath.java:213)
at org.dom4j.xpath.DefaultXPath.selectNodes(DefaultXPath.java:132)
at com.probtp.gp.multitarificateur.referentiel.Referentiel.constitueListePDF(Referentiel.java:250)
at com.probtp.gp.multitarificateur.referentiel.Referentiel.invoque(Referentiel.java:208)
at com.probtp.gp.multitarificateur.referentiel.Referentiel.donner_Referentiel(Referentiel.java:489)
at com.probtp.gp.multitarificateur.referentiel.Referentiel.donner_Referentiel(Referentiel.java:460)
at com.probtp.gp.simulateurs.gammemodulaire.GM_FUEModule.traitementNoticeSpecifique(GM_FUEModule.java:596)
at com.probtp.simulateurs.pdf.PdfMULTI.constitueFicheNotice(PdfMULTI.java:806)
at com.probtp.simulateurs.pdf.PdfMULTI.traiterOffre(PdfMULTI.java:525)
at com.probtp.simulateurs.pdf.PdfMULTI.genererMulti(PdfMULTI.java:407)
at com.probtp.simulateurs.pdf.PdfMULTI.constitutionPDF(PdfMULTI.java:307)
at com.probtp.gp.multitarificateur.action.ChargeMultiValidation.redirectDevis(ChargeMultiValidation.java:1433)
at com.probtp.gp.multitarificateur.action.ChargeMultiValidation.execute(ChargeMultiValidation.java:275)
at com.probtp.gp.ActionGP.perform(ActionGP.java:169)
at probtp.web.base.action.PActionBase.performAction(PActionBase.java:194)
at probtp.web.struts.PAction.perform(PAction.java:119)
at org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.java:1487)
at probtp.web.struts.PActionServlet.process(PActionServlet.java:281)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:557)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1443)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1384)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131)
at probtp.mesures.web.MesuresFilter.doFilter(MesuresFilter.java:281)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
at com.probtp.web.filter.StatsFilter.doFilter(StatsFilter.java:44)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:852)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:785)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:443)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:175)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3610)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:274)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:926)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1557)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:173)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
at com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1772)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
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:202)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:766)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:896)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527)

It's not a coding issue because my team mates don't have this problem and we're supposed to have the same configuration. When I create an EAR and one of my colleagues deploy it locally it works...

I have tried the following modifications without any success :

  • change the compiler from JDK 1.5 to 1.6,
  • try other version of DOM4J (1.6.1 currently),
  • install my server again.

If you have any tips, I would be glad to test it.

Thanks in advance, JB.


Solution

  • Change the classloader policy to match your teammates configuration, there's a few options about how to do that the most straightforward is to change the server classloader:

    Click Servers > Server Types > WebSphere application servers > server_name to access an application server settings page. Specify the application class-loader policy for the application server. Save and restart.

    See further details on how to change the classloader and also other approaches you can take:

    Specify class-loader values for an application server.

    Specify class-loader values for an installed enterprise application.

    Specify the class-loader mode for an installed web module.

    The classloader policy settings are:

    Classes loaded with parent class loader first - Causes the class loader to search in the parent class loader first to load a class. This value is the standard for Development Kit class loaders and WebSphere® Application Server class loaders.

    Classes loaded with local class loader first (parent last) - Causes the class loader to search in the application class loader first to load a class. By specifying Classes loaded with local class loader first (parent last), your application can override classes contained in the parent class loader.

    In short it means If you reference from your code a class in a package com.x.Foo and for instance this exactly same class is present on WebSphere classloader and also in one of your packaged libraries in your WEB-INF/lib folder if you're using the default "parent first" the classloader will find and use the WebSphere version because it will find it first on the other hand if you change it to be "parent last" it will find your libraries version first and than used it instead. Please check the official IBM WebSphere infocenter page about where you'll find a full detailed explanation.