You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2017/10/04 18:18:01 UTC

incubator-freemarker git commit: Bug fixed: On OpenJDK 9 (but not on earlier versions, nor on Oracle Java 9 (tested with build 9+181)), when you try to use the DOM-based XML support (freemarker.ext.dom.NodeModel), unless you happen to have Apache Xalan i

Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3-gae 1986341b9 -> 24d7ecd8a


Bug fixed: On OpenJDK 9 (but not on earlier versions, nor on Oracle Java 9 (tested with build 9+181)), when you try to use the DOM-based XML support (freemarker.ext.dom.NodeModel), unless you happen to have Apache Xalan in the class path, the NodeModel constructor will fail with IllegalAccessError because java.xml does not export com.sun.org.apache.xml.internal.utils. Note that while the exception is not thrown anymore in 2.3.27, FreeMarker can't use the XPath support included in Open JDK 9, and so templates that try to use XPath expressions (like doc['//foo']) will still fail, unless 3rd party XPath support (i.e., Apache Xalan or Jaxen 1.1+) is present.

Also updated related documentation.


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/24d7ecd8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/24d7ecd8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/24d7ecd8

Branch: refs/heads/2.3-gae
Commit: 24d7ecd8a7297c7225d843f34335c4357714b55d
Parents: 1986341
Author: ddekany <dd...@apache.org>
Authored: Wed Oct 4 20:17:53 2017 +0200
Committer: ddekany <dd...@apache.org>
Committed: Wed Oct 4 20:17:53 2017 +0200

----------------------------------------------------------------------
 src/main/java/freemarker/ext/dom/NodeModel.java | 33 ++++++++++++-------
 src/manual/en_US/book.xml                       | 34 ++++++++++++++++----
 2 files changed, 48 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/24d7ecd8/src/main/java/freemarker/ext/dom/NodeModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/dom/NodeModel.java b/src/main/java/freemarker/ext/dom/NodeModel.java
index a4ef7d2..d11bf8a 100644
--- a/src/main/java/freemarker/ext/dom/NodeModel.java
+++ b/src/main/java/freemarker/ext/dom/NodeModel.java
@@ -619,20 +619,35 @@ implements TemplateNodeModelEx, TemplateHashModel, TemplateSequenceModel,
         synchronized (STATIC_LOCK) {
             xpathSupportClass = null;
             jaxenXPathSupport = null;
+            
             try {
                 useXalanXPathSupport();
+            } catch (ClassNotFoundException e) {
+                // Expected
             } catch (Exception e) {
-                ; // ignore
+                LOG.debug("Failed to use Xalan XPath support.", e);
+            } catch (IllegalAccessError e) {
+                LOG.debug("Failed to use Xalan internal XPath support.", e);
             }
+            
             if (xpathSupportClass == null) try {
             	useSunInternalXPathSupport();
             } catch (Exception e) {
-            	; // ignore
+                LOG.debug("Failed to use Sun internal XPath support.", e);
+            } catch (IllegalAccessError e) {
+                // Happens on OpenJDK 9 (but not on Oracle Java 9)
+                LOG.debug("Failed to use Sun internal XPath support. "
+                        + "Tip: On Java 9+, you may need Xalan or Jaxen+Saxpath.", e);
             }
+            
             if (xpathSupportClass == null) try {
                 useJaxenXPathSupport();
+            } catch (ClassNotFoundException e) {
+                // Expected
             } catch (Exception e) {
-                ; // ignore
+                LOG.debug("Failed to use Jaxen XPath support.", e);
+            } catch (IllegalAccessError e) {
+                LOG.debug("Failed to use Jaxen XPath support.", e);
             }
         }
     }
@@ -648,9 +663,7 @@ implements TemplateNodeModelEx, TemplateHashModel, TemplateSequenceModel,
         synchronized (STATIC_LOCK) {
             xpathSupportClass = c;
         }
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Using Jaxen classes for XPath support");
-        }
+        LOG.debug("Using Jaxen classes for XPath support");
     }
     
     /**
@@ -663,9 +676,7 @@ implements TemplateNodeModelEx, TemplateHashModel, TemplateSequenceModel,
         synchronized (STATIC_LOCK) {
             xpathSupportClass = c;
         }
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Using Xalan classes for XPath support");
-        }
+        LOG.debug("Using Xalan classes for XPath support");
     }
     
     static public void useSunInternalXPathSupport() throws Exception {
@@ -674,9 +685,7 @@ implements TemplateNodeModelEx, TemplateHashModel, TemplateSequenceModel,
         synchronized (STATIC_LOCK) {
             xpathSupportClass = c;
         }
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Using Sun's internal Xalan classes for XPath support");
-        }
+        LOG.debug("Using Sun's internal Xalan classes for XPath support");
     }
     
     /**

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/24d7ecd8/src/manual/en_US/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index 2799c57..5e29074 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -24619,14 +24619,17 @@ Test Book</programlisting>
         <section>
           <title>Using XPath expressions</title>
 
-          <note>
+          <note xml:id="topic.xpathSupportDependencies">
             <para>XPath expressions work only if <link
-            xlink:href="http://jaxen.org/">Jaxen</link> (recommended, but use
-            at least Jaxen 1.1-beta-8, not older) or <link
-            xlink:href="http://xml.apache.org/xalan/">Apache Xalan</link>
-            classes are available. (Apache Xalan classes are included in Sun
-            J2SE 1.4, 1.5 and 1.6 (and maybe later too); no separate Xalan jar
-            is needed.)</para>
+            xlink:href="http://xml.apache.org/xalan/">Apache Xalan</link> or
+            <link xlink:href="http://jaxen.org/">Jaxen</link> (at least 1.1)
+            classes are available. However, up to Java 1.8 you don't need any
+            additional dependencies, as Apache Xalan is included in Java with
+            changed package names, which FreeMarker will automatically use
+            (unless plain Apache Xalan is also present). This internal Xalan
+            isn't available anymore on OpenJDK 9, but is still available on
+            Oracle JDK/JRE 9 (at least on official stable release <quote>build
+            9+181</quote>).</para>
           </note>
 
           <note>
@@ -27220,6 +27223,23 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
             </listitem>
 
             <listitem>
+              <para>Bug fixed: On OpenJDK 9 (but not on earlier versions, nor
+              on Oracle Java 9 (tested with <quote>build 9+181</quote>)), when
+              you try to use the DOM-based XML support
+              (<literal>freemarker.ext.dom.NodeModel</literal>), unless you
+              happen to have Apache Xalan in the class path, the
+              <literal>NodeModel</literal> constructor will fail with
+              <literal>IllegalAccessError</literal> because <quote>java.xml
+              does not export com.sun.org.apache.xml.internal.utils</quote>.
+              Note that while the exception is not thrown anymore in 2.3.27,
+              FreeMarker can't use the XPath support included in Open JDK 9,
+              and so templates that try to use XPath expressions (like
+              <literal>doc['//foo']</literal>) will still fail, <link
+              linkend="topic.xpathSupportDependencies">unless 3rd party XPath
+              support is present</link>.</para>
+            </listitem>
+
+            <listitem>
               <para>Bug fixed: When the
               <literal>TemplateExceptionHandler</literal> suppresses (i.e.,
               doesn't re-throw) an exception, the <link