-
Bug
-
Resolution: Fixed
-
P2
-
9
Let's consider code below:
import javax.xml.bind.*;
import java.util.Map;
public class Test7 {
private static JAXBContext tmp;
public static abstract class FactoryBase implements JAXBContextFactory {
@Override
public JAXBContext createContext(Class<?>[] classesToBeBound, Map<String, ?> properties) throws JAXBException {
return tmp;
}
@Override
public JAXBContext createContext(String contextPath, ClassLoader classLoader, Map<String, ?> properties)
throws JAXBException {
return tmp;
}
}
public static class Factory extends FactoryBase {}
public static void main(String[] args) throws JAXBException {
tmp = JAXBContext.newInstance(Test7.class);
System.setProperty(JAXBContext.JAXB_CONTEXT_FACTORY, "Test7$Factory");
JAXBContext.newInstance(Test7.class);
}
}
It causes following output on JDK9b104 however it should have succeeded:
Exception in thread "main" javax.xml.bind.JAXBException: Provider class Test7$FactoryBase could not be instantiated: java.security.PrivilegedActionException: java.lang.InstantiationException
- with linked exception:
[java.security.PrivilegedActionException: java.lang.InstantiationException]
at javax.xml.bind.ContextFinder.instantiateProviderIfNecessary(ContextFinder.java:244)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:274)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:265)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:369)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:659)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:603)
at Test7.main(Test7.java:25)
Disconnected from the target VM, address: '127.0.0.1:61426', transport: 'socket'
Caused by: java.security.PrivilegedActionException: java.lang.InstantiationException
at java.security.AccessController.doPrivileged(Native Method)
at javax.xml.bind.ContextFinder.instantiateProviderIfNecessary(ContextFinder.java:235)
... 6 more
Caused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
at java.lang.reflect.Constructor.newInstance(Constructor.java:426)
at java.lang.Class.newInstance(Class.java:466)
at javax.xml.bind.ContextFinder$2.run(ContextFinder.java:238)
... 8 more
import javax.xml.bind.*;
import java.util.Map;
public class Test7 {
private static JAXBContext tmp;
public static abstract class FactoryBase implements JAXBContextFactory {
@Override
public JAXBContext createContext(Class<?>[] classesToBeBound, Map<String, ?> properties) throws JAXBException {
return tmp;
}
@Override
public JAXBContext createContext(String contextPath, ClassLoader classLoader, Map<String, ?> properties)
throws JAXBException {
return tmp;
}
}
public static class Factory extends FactoryBase {}
public static void main(String[] args) throws JAXBException {
tmp = JAXBContext.newInstance(Test7.class);
System.setProperty(JAXBContext.JAXB_CONTEXT_FACTORY, "Test7$Factory");
JAXBContext.newInstance(Test7.class);
}
}
It causes following output on JDK9b104 however it should have succeeded:
Exception in thread "main" javax.xml.bind.JAXBException: Provider class Test7$FactoryBase could not be instantiated: java.security.PrivilegedActionException: java.lang.InstantiationException
- with linked exception:
[java.security.PrivilegedActionException: java.lang.InstantiationException]
at javax.xml.bind.ContextFinder.instantiateProviderIfNecessary(ContextFinder.java:244)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:274)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:265)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:369)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:659)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:603)
at Test7.main(Test7.java:25)
Disconnected from the target VM, address: '127.0.0.1:61426', transport: 'socket'
Caused by: java.security.PrivilegedActionException: java.lang.InstantiationException
at java.security.AccessController.doPrivileged(Native Method)
at javax.xml.bind.ContextFinder.instantiateProviderIfNecessary(ContextFinder.java:235)
... 6 more
Caused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
at java.lang.reflect.Constructor.newInstance(Constructor.java:426)
at java.lang.Class.newInstance(Class.java:466)
at javax.xml.bind.ContextFinder$2.run(ContextFinder.java:238)
... 8 more
- relates to
-
JDK-8145104 NPE is thrown when JAXBContextFactory implementation is specified in system property
-
- Closed
-