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

Confusion between bootstrap and system class loaders in FactoryFinder.findJarServiceProvider

    Details

    • Subcomponent:
    • Resolved In Build:
      b142
    • CPU:
      x86
    • OS:
      linux
    • Verification:
      Not verified

      Backports

        Description

        For background, see:

        http://www.netbeans.org/nonav/issues/show_bug.cgi?id=139048

        To reproduce, run the following with Apache Xerces in the classpath:

        ---%<---
        import java.net.URL;
        import java.net.URLClassLoader;
        import javax.xml.parsers.SAXParserFactory;
        public class TestJAXP {
            public static void main(String[] args) throws Exception {
                Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0], ClassLoader.getSystemClassLoader().getParent()));
                SAXParserFactory.newInstance();
            }
        }
        ---%<---

        Under JDK 6 I get:

        Exception in thread "main" javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found
                at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:134)
                at TestJAXP.main(TestJAXP.java:7)

        The reason is that FactoryFinder.findJarServiceProvider behaves as follows:

        1. Check the thread's CCL for META-INF/services/javax.xml.parsers.SAXParserFactory. This is not found, since the CCL does not see the app class loader.

        2. is == null, so set cl = null (bootstrap loader), and call SecuritySupport.getResourceAsStream.

        3. ClassLoader.getSystemResourceAsStream(...) returns the resources from xerces.jar, because it checks the app class loader, not the bootstrap loader (which has no such resource).

        4. newInstance(null, "org.apache.xerces....", false) is called, which asks for org.apache.xerces... from the CCL, which cannot see it.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  joehw Joe Wang
                  Reporter:
                  jglick Jesse Glick (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: