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

NPE is thrown when JAXBContextFactory implementation is specified in system property

    Details

    • Subcomponent:
    • Introduced In Build:
      b94
    • Introduced In Version:
      9
    • Resolved In Build:
      b104
    • Verification:
      Verified

      Description

      Let's consider the code below:

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

      public class Test3 {
          public static class Factory implements JAXBContextFactory {
              @Override
              public JAXBContext createContext(Class<?>[] classesToBeBound, Map<String, ?> properties) throws JAXBException {
                  throw new Error();
              }

              @Override
              public JAXBContext createContext(String contextPath, ClassLoader classLoader, Map<String, ?> properties)
                      throws JAXBException {
                  throw new Error();
              }
          }
          public static void main(String[] args) throws JAXBException {
              System.setProperty(JAXBContext.JAXB_CONTEXT_FACTORY, "Test3$Factory");
              try {
                  JAXBContext.newInstance(Test3.class);
              } catch (Throwable t) {
                  t.printStackTrace();
              }
          }
      }

      This code produces following stack trace when being run on JDKb94:

      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:355)
      at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
      at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:606)
      at Test3.main(Test3.java:29)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mkos Miroslav Kos (Inactive)
                Reporter:
                grakov Georgiy Rakov (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: