diff --git a/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/JAXPXPathEvaluator.java b/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/JAXPXPathEvaluator.java index abe4d6c5ff..e7e0e57368 100644 --- a/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/JAXPXPathEvaluator.java +++ b/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/JAXPXPathEvaluator.java @@ -19,6 +19,7 @@ package org.apache.activemq.artemis.selector.filter; import javax.xml.parsers.DocumentBuilder; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import java.io.StringReader; import org.slf4j.Logger; @@ -36,6 +37,7 @@ public class JAXPXPathEvaluator implements XPathExpression.XPathEvaluator { private final String xpathExpression; private final XPath xpath; private final DocumentBuilder builder; + private final javax.xml.xpath.XPathExpression compiledXPathExpression; public JAXPXPathEvaluator(String xpathExpression, DocumentBuilder builder) { this.xpathExpression = xpathExpression; @@ -43,6 +45,12 @@ public class JAXPXPathEvaluator implements XPathExpression.XPathEvaluator { synchronized (FACTORY) { this.xpath = FACTORY.newXPath(); } + + try { + this.compiledXPathExpression = xpath.compile(xpathExpression); + } catch (XPathExpressionException e) { + throw new IllegalArgumentException(e); + } } @Override @@ -61,7 +69,7 @@ public class JAXPXPathEvaluator implements XPathExpression.XPathEvaluator { protected boolean evaluate(InputSource inputSource) { try { synchronized (builder) { - return ((Boolean)xpath.evaluate(xpathExpression, builder.parse(inputSource), XPathConstants.BOOLEAN)).booleanValue(); + return ((Boolean)compiledXPathExpression.evaluate(builder.parse(inputSource), XPathConstants.BOOLEAN)).booleanValue(); } } catch (Exception e) { logger.debug("Failed to evaluate XPath expression {}", xpathExpression, inputSource, e);