NullPointerException in JAXBContext.newInstance ()

Java developer. I use JAXB to create binding objects. When I try to create a JAXBContext as follows:

 JAXBContext.newInstance("com.mycompany.jaxb.pkg1:com.mycompany.jaxb.pkg2"); 

I get a NullPointerException:

 Exception in thread "main" java.lang.NullPointerException at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.calcXmlName(PropertyInfoImpl.java:287) at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.calcXmlName(PropertyInfoImpl.java:260) at com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl.getTypes(ElementPropertyInfoImpl.java:100) at com.sun.xml.bind.v2.model.impl.RuntimeElementPropertyInfoImpl.getTypes(RuntimeElementPropertyInfoImpl.java:50) at com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl$1.size(ElementPropertyInfoImpl.java:42) at java.util.AbstractList$Itr.hasNext(AbstractList.java:416) at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:139) at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:49) at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:41) at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:189) at com.sun.xml.bind.v2.model.impl.RegistryInfoImpl.<init>(RegistryInfoImpl.java:63) at com.sun.xml.bind.v2.model.impl.ModelBuilder.addRegistry(ModelBuilder.java:232) at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:201) at com.sun.xml.bind.v2.runtime.JAXBContextImpl$3.run(JAXBContextImpl.java:357) at com.sun.xml.bind.v2.runtime.JAXBContextImpl$3.run(JAXBContextImpl.java:351) at java.security.AccessController.doPrivileged(Native Method) at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:350) at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:216) at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:76) at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:55) at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:124) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:592) at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:132) at javax.xml.bind.ContextFinder.find(ContextFinder.java:286) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244) at com.mycompany.jaxb.JAXBContextFactory.initIfNeeded(JAXBContextFactory.java:66) 

Google for relevant keywords has led me to several discussion topics saying this is a known bug and I should upgrade to version 2.0.3. But here is my POM maven file:

 <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> <version>2.2.1</version> </dependency> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.1</version> </dependency> 

... as you can see, I'm already out of version 2.0.3. (And yes, I tried to revert to the old version, this did not help.)

Has anyone seen this for a reason other than version 2.0.2 or later, or does anyone have pointers on how to solve the problem?

+4
source share
1 answer

Ok, for the record: I found a solution.

As suggested by several threads, the source of this error was the JAXB version, which was older than 2.0.2. My mistake was that my POM maven file was overridden by another POM file that imported an older version of the library.

Thanks to the scaffman and everyone else who looked.

+2
source

Source: https://habr.com/ru/post/1333851/


All Articles