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

XPathFactory.newInstance() silently swallows RuntimeException(s)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 5.0
    • xml

      FULL PRODUCT VERSION :
      All

      A DESCRIPTION OF THE PROBLEM :
      the XPathFactory.newInstance() silently swallows all RuntimeException(s) thrown by the constructor of the factory implementation, and silently defaults to the platform factory.


      REPRODUCIBILITY :
      This bug can be reproduced often.

      CUSTOMER SUBMITTED WORKAROUND :
      Apply this partial patch to fix exception thrown by factories configured by META-INF/services/javax.xml.xpath.XPathFactory

      diff -U3 -r src/javax/xml/xpath/XPathFactoryFinder.java srcx/javax/xml/xpath/XPathFactoryFinder.java
      --- src/javax/xml/xpath/XPathFactoryFinder.java Fri Mar 4 00:26:36 2005
      +++ srcx/javax/xml/xpath/XPathFactoryFinder.java Tue Apr 12 22:55:51 2005
      @@ -149,7 +149,7 @@
                       if(sf!=null) return sf;
                   } else
                       debugPrintln("The property is undefined.");
      - } catch( Throwable t ) {
      + } catch( Exception t ) {
                   if( debug ) {
                       debugPrintln("failed to look up system property '"+propertyName+"'" );
                       t.printStackTrace();
      @@ -242,7 +242,9 @@
                       return (XPathFactory)o;
                   
                   debugPrintln(className+" is not assignable to "+SERVICE_CLASS.getName());
      - } catch( Throwable t ) {
      + } catch( RuntimeException e) {
      + throw e;
      + } catch( Exception t ) {
                   debugPrintln("failed to instanciate "+className);
                   if(debug) t.printStackTrace();
               }
      @@ -294,6 +296,7 @@
            */
           private Iterator createServiceFileIterator() {
               if (classLoader == null) {
      + debugPrintln("no classloader found to retrieve "+SERVICE_ID);
                   return new SingleIterator() {
                       protected Object value() {
                           ClassLoader classLoader = XPathFactoryFinder.class.getClassLoader();
      @@ -303,6 +306,7 @@
                   };
               } else {
                   try {
      + debugPrintln("using "+classLoader+" to retrieve "+SERVICE_ID);
                       //final Enumeration e = classLoader.getResources(SERVICE_ID);
                       final Enumeration e = ss.getResources(classLoader, SERVICE_ID);
                       if(!e.hasMoreElements()) {


      Anyhow, this might happen in other cases even after the patch is applied.

            joehw Joe Wang
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: