Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2463

XPathExpressionImpl is not thread safe (unsafe use of static DocumentBuilder object instance)

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.7.1
    • Fix Version/s: None
    • Component/s: XPath
    • Security Level: No security risk; visible to anyone (Ordinary problems in Xalan projects. Anybody can view the issue.)
    • Labels:
      None

      Description

      XPathExpressionImpl is not thread safe (unsafe use of static DocumentBuilder object instance).

      See code snippet from XPathExpressionImpl below (note the use of the static db member and the fact that evaluate could be called for different XPathExpressionImpl instances simultaneously):

      static DocumentBuilderFactory dbf = null;
      static DocumentBuilder db = null;
      static Document d = null;

      public Object evaluate(InputSource source, QName returnType)
      throws XPathExpressionException {
      if ( ( source == null ) || ( returnType == null ) )

      { String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_SOURCE_RETURN_TYPE_CANNOT_BE_NULL, null ); throw new NullPointerException ( fmsg ); }

      // Checking if requested returnType is supported. returnType need to be
      // defined in XPathConstants
      if ( !isSupported ( returnType ) ) {
      String fmsg = XSLMessages.createXPATHMessage(
      XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
      new Object[]

      { returnType.toString() }

      );
      throw new IllegalArgumentException ( fmsg );
      }
      try {
      if ( dbf == null )

      { dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware( true ); dbf.setValidating( false ); }

      db = dbf.newDocumentBuilder();
      Document document = db.parse( source );
      return eval( document, returnType );
      } catch ( Exception e )

      { throw new XPathExpressionException ( e ); }

      }

      Exception looks like:
      Caused by: javax.xml.xpath.XPathExpressionException
      at org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:298)
      at org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:325)
      at test.TestXalanXPath$Runner.run(TestXalanXPath.java:49)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
      Caused by: org.xml.sax.SAXException: FWK005 parse may not be called while parsing.
      at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
      at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
      at org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:295)
      ... 5 more

        Attachments

        1. XPathExpressionImpl.java
          16 kB
          PJ Fanning
        2. TestXalanXPath.zip
          2 kB
          PJ Fanning

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              pj.fanning PJ Fanning
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: