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

XMLEventFactory.newFactory(String factoryId, ClassLoader loader) does not work as expected

    Details

    • Subcomponent:
    • Resolved In Build:
      b06
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Backports

        Description

        It looks XMLEventFactory.newFactory(String factoryId, ClassLoader classLoader) does not work as expected.

        As java doc, factoryId should be "Name of the factory to find, same as a property name".
        But actually it is treated as "property value". See below test code. I believe the bug is similar with CR 6756677, which treat factoryId as property value for XMLInputFactory.

        It happens for latest build of 7u4, 7u6 and 8.

        Simple test code:
        =========================
        package javax.xml.stream;

        import javax.xml.stream.* ;

        public class Test{
        public static void main(String[] args){
            System.setProperty("inputFac", "javax.xml.stream.MyInputFactory") ;
            System.setProperty("outputFac", "javax.xml.stream.MyOutputFactory") ;
            System.setProperty("eventFac", "javax.xml.stream.MyEventFactory") ;
           
            XMLInputFactory xif = XMLInputFactory.newFactory("inputFac", null);
            System.out.println(xif.getClass().getName()) ;


            XMLOutputFactory xof = XMLOutputFactory.newFactory("outputFac", null);
            System.out.println(xof.getClass().getName()) ;

            //work
                XMLEventFactory xef1 = XMLEventFactory.newFactory("javax.xml.stream.MyEventFactory", null);
                System.out.println(xef1.getClass().getName()) ;

            //do not work
                XMLEventFactory xef2 = XMLEventFactory.newFactory("eventFac", null);
                System.out.println(xef2.getClass().getName()) ;

        }
        }
        ==============

        Output:
        =============
        javax.xml.stream.MyInputFactory
        javax.xml.stream.MyOutputFactory
        javax.xml.stream.MyEventFactory
        Exception in thread "main" javax.xml.stream.FactoryConfigurationError: Provider eventFac not found
            at javax.xml.stream.XMLEventFactory.newFactory(XMLEventFactory.java:147)
            at javax.xml.stream.Test.main(Test.java:23)
        Caused by: java.lang.ClassNotFoundException: eventFac
            at java.net.URLClassLoader$1.run(URLClassLoader.java:359)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
            at javax.xml.stream.FactoryFinder.getProviderClass(FactoryFinder.java:108)
            at javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:143)
            at javax.xml.stream.XMLEventFactory.newFactory(XMLEventFactory.java:144)
            ... 1 more
        =============

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  joehw Joe Wang
                  Reporter:
                  pzhang Patrick Zhang (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: