Uploaded image for project: 'XMLBeans'
  1. XMLBeans
  2. XMLBEANS-506

NPE trying to load resource file if XmlBeans was loaded by the bootstrap ClassLoader

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: Version 2.5, Version 2.6
    • Fix Version/s: Version 3.0.2
    • Component/s: None
    • Labels:
      None
    • Environment:
      JBoss 6.1.0, JVM 1.6.0_30, CentOS 5.7 x86_64

      Description

      To solve a dependency issue, we put XmlBeans 2.5.0 into the endorsed folder. This brought the following exception:

      java.lang.NullPointerException
      at org.apache.xmlbeans.impl.store.Path.<clinit>(Path.java:65)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:169)
      at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.getMethod(SchemaTypeLoaderBase.java:73)
      at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.<clinit>(SchemaTypeLoaderBase.java:66)
      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:597)
      at org.apache.xmlbeans.XmlBeans.getNoType(XmlBeans.java:856)
      at org.apache.xmlbeans.XmlBeans.<clinit>(XmlBeans.java:881)

      The source code of org.apache.xmlbeans.impl.store.Path looks like this:

      63: ClassLoader cl = Path.class.getClassLoader();
      64: String id = "META-INF/services/org.apache.xmlbeans.impl.store.PathDelegate.SelectPathInterface";
      65: InputStream in = cl.getResourceAsStream(id); <- NPE occurs here

      This appears to be a bug. The JavaDoc for getClassLoader() says: "Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader." So the caller of getClassLoader() should take into account that it might return null, which does not happen here. I would suggest changing line 65 to the following:

      InputStream in = Path.class.getResourceAsStream(id);

      Note: The Class method works slightly different. If the resource name does not contain a path it will look for the file in the package where the Class is located.

      I checked XmlBeans 2.6.0 and browsed the SVN sources, the problem still exists.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                pj.fanning PJ Fanning
                Reporter:
                dhengst Daniel Hengst
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: