Commons JXPath
  1. Commons JXPath
  2. JXPATH-76

CompiledExpression not completely thread-safe


    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2 Final
    • Fix Version/s: 1.3
    • Labels:


      Some classes in compiled expressions are not thread-safe, because they lazily initialize some information that should be initialized at object construction. The classes I've found are Path and ExpressionPath. I've attached a path that fixes the problem.

      When two threads tried to initialize such an object concurrently, it was possible that the expression was evaluated as simple expression when it should have been evaluated as complex expression. See the two stack traces below (using xpath expression //ExternalData/Order/@id). The first stack trace shows the bug in action, the second how it should look:

      caused by java.lang.UnsupportedOperationException: Not supported node test for attributes: node()
      at org.apache.commons.jxpath.ri.axes.SimplePathInterpreter.getNodeIterator( Code))
      at org.apache.commons.jxpath.ri.axes.SimplePathInterpreter.doStepNoPredicatesStandard( Code))
      at org.apache.commons.jxpath.ri.axes.SimplePathInterpreter.doStep( Code))
      at org.apache.commons.jxpath.ri.axes.SimplePathInterpreter.interpretSimpleLocationPath( Compiled Code))
      at org.apache.commons.jxpath.ri.compiler.Path.getSingleNodePointerForSteps( Compiled Code))
      at org.apache.commons.jxpath.ri.compiler.LocationPath.computeValue( Code))
      at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getPointer( Code))
      at org.apache.commons.jxpath.ri.JXPathCompiledExpression.selectSingleNode( Compiled Code))

      This replaces the lines starting at Path.getSingleNodePointerForSteps:

      LocationPath(Path).searchForPath(EvalContext) line: 183
      LocationPath(Path).getSingleNodePointerForSteps(EvalContext) line: 159

      1. jxpath.patch
        3 kB
        Simon Raess


        Simon Raess created issue -
        Simon Raess made changes -
        Field Original Value New Value
        Attachment jxpath.patch [ 12350023 ]
        Simon Raess made changes -
        Affects Version/s 1.2 Final [ 12311699 ]
        Matt Benson made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.3 [ 12312253 ]


          • Assignee:
            Simon Raess
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: