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

Deprecated loader mechanism (step 4) fails to load factory implementing JAXBContextFactory (NPE)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • None
    • 9
    • xml
    • b94
    • 9

      For the purpose of JAXB 2.3 implementation discovery spec allows to configure deprecated loader mechanism to load regular factory that is factory implementing JAXBContextFactory. In this case NPE is thrown.

      Let's consider following code:

      import javax.xml.bind.JAXBContext;
      import javax.xml.bind.JAXBContextFactory;
      import javax.xml.bind.JAXBException;
      import java.util.Map;

      public class Test5 {

          public static class FactoryInstance implements JAXBContextFactory {

              @Override
              public JAXBContext createContext(Class<?>[] classesToBeBound, Map<String, ?> properties) throws JAXBException {
                  System.out.println("createContext(Class[], ...)");
                  return null;
              }

              @Override
              public JAXBContext createContext(String contextPath, ClassLoader classLoader, Map<String, ?> properties)
                      throws JAXBException {
                  System.out.println("createContext(String, ...)");
                  return null;
              }
          }

          public static void main(String[] args) throws JAXBException {
              try {
                  JAXBContext.newInstance(Test5.class);
              } catch (Throwable t) {
                  t.printStackTrace();
              }
          }
      }

      When deprecated loader is configure to load Test5$FactoryInstance NPE is thrown:

      java.lang.NullPointerException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:520)
      at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:258)
      at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:249)
      at javax.xml.bind.ContextFinder.find(ContextFinder.java:364)
      at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
      at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:606)
      at Test5.main(Test5.java:26)

      Minimized testcase is attached.

            grakov Georgiy Rakov (Inactive)
            grakov Georgiy Rakov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: