Web Service client rarely got NullPointerException inside Apache CXF code included in EAP 6.x and 7.x

Solution Unverified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x
    • 7.x
  • Apache CXF

Issue

Web Service client rarely failed with the following NullPointerException in Apache CXF included in EAP 6.x and 7.x:

java.lang.NullPointerException
	at org.apache.cxf.common.jaxb.JAXBUtils.createJAXBContextProxy(JAXBUtils.java:1425)
	at org.apache.cxf.jaxb.JAXBDataBinding.checkForJAXBAnnotations(JAXBDataBinding.java:433)
	at org.apache.cxf.jaxb.JAXBDataBinding.justCheckForJAXBAnnotations(JAXBDataBinding.java:427)
	at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:363)
	at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
	at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:446)
	at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:548)
	at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:265)
	at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:215)
	at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102)
	at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:91)
	at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:157)
	at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:142)
	at org.apache.cxf.jaxws.ServiceImpl.createPort(ServiceImpl.java:478)
	at org.jboss.wsf.stack.cxf.client.ProviderImpl$JBossWSServiceImpl.createPort(ProviderImpl.java:558)
	at org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:329)
	at org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:324)
	at javax.xml.ws.Service.getPort(Service.java:168) [jboss-jaxws-api_2.2_spec-2.0.2.Final-redhat-1.jar:2.0.2.Final-redhat-1]
        ...(snip)...

Resolution

This issue is a bug reported in the following bugzila and JIRAs:

Please upgrade to the following releases when it's is available:

Root Cause

  • This phenomenon occurs when Full GC happens before calling CachedContextAndSchemasInternal#getContext() in a constructor of org.apache.cxf.common.jaxb.JAXBContextCache$CachedContextAndSchemas. "WeakReference<JAXBContext> context" inside org.apache.cxf.common.jaxb.JAXBContextCache$CachedContextAndSchemasInternal is cleared at the Full GC and CachedContextAndSchemasInternal#getContext() returns null.
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.