FREEMARKER-104: In log and error messages due to no XPath implementation available, recommend adding Apache Xalan or Jaxen as dependency.
diff --git a/src/main/java/freemarker/ext/dom/NodeListModel.java b/src/main/java/freemarker/ext/dom/NodeListModel.java
index 0d0c4e3..6da6566 100644
--- a/src/main/java/freemarker/ext/dom/NodeListModel.java
+++ b/src/main/java/freemarker/ext/dom/NodeListModel.java
@@ -173,8 +173,8 @@
XPathSupport xps = getXPathSupport();
if (xps == null) {
throw new TemplateModelException(
- "Can't try to resolve the XML query key, because no XPath support is available. "
- + "This is either malformed or an XPath expression: " + key);
+ "No XPath support is available (add Apache Xalan or Jaxen as dependency). "
+ + "This is either malformed, or an XPath expression: " + key);
}
Object context = (size == 0) ? null : rawNodeList();
return xps.executeQuery(context, key);
diff --git a/src/main/java/freemarker/ext/dom/NodeModel.java b/src/main/java/freemarker/ext/dom/NodeModel.java
index 6d5f08f..411e0bd 100644
--- a/src/main/java/freemarker/ext/dom/NodeModel.java
+++ b/src/main/java/freemarker/ext/dom/NodeModel.java
@@ -107,7 +107,7 @@
// do nothing
}
if (xpathSupportClass == null && LOG.isWarnEnabled()) {
- LOG.warn("No XPath support is available.");
+ LOG.warn("No XPath support is available. If you need it, add Apache Xalan or Jaxen as dependency.");
}
}
@@ -334,13 +334,12 @@
}
} else {
XPathSupport xps = getXPathSupport();
- if (xps != null) {
- return xps.executeQuery(node, key);
- } else {
+ if (xps == null) {
throw new TemplateModelException(
- "Can't try to resolve the XML query key, because no XPath support is available. "
- + "This is either malformed or an XPath expression: " + key);
+ "No XPath support is available (add Apache Xalan or Jaxen as dependency). "
+ + "This is either malformed, or an XPath expression: " + key);
}
+ return xps.executeQuery(node, key);
}
}
@@ -440,7 +439,7 @@
return other.getClass() == this.getClass()
&& ((NodeModel) other).node.equals(this.node);
}
-
+
static public NodeModel wrap(Node node) {
if (node == null) {
return null;
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index bf08308..1ea161b 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -27633,6 +27633,19 @@
<itemizedlist>
<listitem>
+ <para><link
+ xlink:href="https://issues.apache.org/jira/browse/FREEMARKER-104">FREEMARKER-104</link>:
+ More helpful log and error messages (especially, no
+ <literal>NullPointerException</literal> cause exception logged
+ during FreeMarker XPath support initialization) if no XPath
+ implementation is available because Java 9 modules don't allow
+ accessing the internal Xalan that's stored under
+ <literal>com.sun</literal> packages. (The messages now recommend
+ adding Apache Xalan or Jaxen as dependency if you need XPath
+ support.)</para>
+ </listitem>
+
+ <listitem>
<para>Added
<literal>TemplateModelUtils.wrapAsHashUnion(ObjectWrapper,
List<?>)</literal> and