Reputation: 463
I am working on some SOAP call in a java application, and unfortunately I saw a very nasty issue and I have no idea how to solve it.
The stacktrace of the NullPointerException is the following:
ava.lang.reflect.InvocationTargetException: null
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at jakarta.xml.bind.ServiceLoaderUtil.lookupsUsingOSGiServiceLoader(ServiceLoaderUtil.java:86)
at jakarta.xml.bind.ContextFinder.find(ContextFinder.java:325)
at jakarta.xml.bind.JAXBContext.newInstance(JAXBContext.java:392)
at jakarta.xml.bind.JAXBContext.newInstance(JAXBContext.java:349)
at jakarta.xml.bind.JAXBContext.newInstance(JAXBContext.java:260)
at org.springframework.oxm.jaxb.Jaxb2Marshaller.createJaxbContextFromContextPath(Jaxb2Marshaller.java:545)
at org.springframework.oxm.jaxb.Jaxb2Marshaller.getJaxbContext(Jaxb2Marshaller.java:505)
at org.springframework.oxm.jaxb.Jaxb2Marshaller.createMarshaller(Jaxb2Marshaller.java:729)
at org.springframework.oxm.jaxb.Jaxb2Marshaller.marshal(Jaxb2Marshaller.java:704)
at org.springframework.ws.support.MarshallingUtils.marshal(MarshallingUtils.java:80)
at org.springframework.ws.client.core.WebServiceTemplate$2.doWithMessage(WebServiceTemplate.java:399)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:569)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:539)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:391)
at de.allianz.bluebird.api.contract.service.abs.leben.FindGevoArtenService.findGeVoArten(FindGevoArtenService.java:166)
at de.allianz.bluebird.api.contract.service.abs.leben.FindGevoArtenService.findGeVoArtenForContract(FindGevoArtenService.java:60)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:751)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89)
at de.allianz.mazapp.commons.resilience.TimeoutAspect.lambda$timeLimiterAroundAdvice$4(TimeoutAspect.java:110)
at io.github.resilience4j.core.ContextPropagator.lambda$decorateSupplier$6(ContextPropagator.java:107)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.NullPointerException: Cannot invoke "org.glassfish.hk2.osgiresourcelocator.ServiceLoader.lookupProviderClasses1(java.lang.Class)" because "org.glassfish.hk2.osgiresourcelocator.ServiceLoader._me" is null
at org.glassfish.hk2.osgiresourcelocator.ServiceLoader.lookupProviderClasses(ServiceLoader.java:132)
And it is obvious where the problem comes from - the method "lookupProviderClasses1" of the org.glassfish.hk2.osgiresourcelocator.ServiceLoader is the following:
public static <T> Iterable<Class> lookupProviderClasses(Class<T> serviceClass) {
return _me.lookupProviderClasses1(serviceClass);
}
and obviously _me is null. It should be initialised via the initialize() method :
public static synchronized void initialize(ServiceLoader singleton) {
if (singleton == null) throw new NullPointerException("Did you intend to call reset()?");
if (_me != null) throw new IllegalStateException("Already initialzed with [" + _me + "]");
_me = singleton;
}
But this method is never called in the ServiceLoaderUtil.lookupsUsingOSGiServiceLoader
private static final String OSGI_SERVICE_LOADER_CLASS_NAME = "org.glassfish.hk2.osgiresourcelocator.ServiceLoader";
private static final String OSGI_SERVICE_LOADER_METHOD_NAME = "lookupProviderClasses";
static <T> Iterable<T> lookupsUsingOSGiServiceLoader(String factoryId, Logger logger) {
try {
// Use reflection to avoid having any dependency on ServiceLoader class
return (Iterable<T>)
Class.forName(OSGI_SERVICE_LOADER_CLASS_NAME)
.getMethod(OSGI_SERVICE_LOADER_METHOD_NAME, Class.class)
.invoke(null, Class.forName(factoryId));
} catch (IllegalAccessException |
InvocationTargetException |
ClassNotFoundException |
NoSuchMethodException ex) {
logger.log(Level.FINE, ex, () -> "Unable to find from OSGi: [" + factoryId + "]");
return null;
}
}
Does anyone know what can be done in this situation? I have the feeling, that JAXBContextFactory has to be defined, because in the context finder I see the following:
JAXBContextFactory obj = ServiceLoaderUtil.firstByServiceLoader(
JAXBContextFactory.class, logger, EXCEPTION_HANDLER);
if (obj != null) {
ModuleUtil.delegateAddOpensToImplModule(contextPathClasses, obj.getClass());
return obj.createContext(contextPath, classLoader, properties);
}
Iterable<Class<? extends JAXBContextFactory>> ctxFactories = ServiceLoaderUtil.lookupsUsingOSGiServiceLoader(
JAXBContext.JAXB_CONTEXT_FACTORY, logger);
so if the ServiceLoaderUtil.firstByServiceLoader finds a JAXBContextFactory, it will return it an will not have to search via OSGiServiceLoader (and respectfully get the NullPointerException)?
Upvotes: 0
Views: 205