Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8150173

JAXBContext.newInstance causes PrivilegedActionException when createContext's declared in abstract class extended by discovered JAXB implementation

XMLWordPrintable

    • b104
    • 9
    • b125
    • Verified

      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

        1. Test7.java
          0.9 kB
          Georgiy Rakov

            dfuchs Daniel Fuchs
            grakov Georgiy Rakov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: