Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8015487

TransformerFactory.newTransformer crashing with external Xerces

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2 P2
    • 8
    • 7u40, 8
    • xml
    • $ java -version
      java version "1.8.0-ea"
      Java(TM) SE Runtime Environment (build 1.8.0-ea-b91)
      Java HotSpot(TM) 64-Bit Server VM (build 25.0-b33, mixed mode)

    • b91
    • 8

      This code snippet:
      -------
      package transform.test;

      import java.net.URL;
      import javax.xml.transform.TransformerFactory;
      import javax.xml.transform.stream.StreamSource;

      public class TransformTest {
          public static void main(String[] args) throws Exception {
              TransformerFactory tf = TransformerFactory.newInstance();
              URL xsl = TransformTest.class.getResource("build.xsl");
              StreamSource stylesheetSource = new StreamSource(
                  xsl.openStream(), xsl.toExternalForm());
              tf.newTransformer(stylesheetSource);
          }
      }
      -------

      may fail with the exception attached as "transformation-exception.txt" when xerces-2.8.0 is on the classpath. The cause of this exception is
      jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java:479
      where the XMLConstants.ACCESS_EXTERNAL_DTD property is set into the parser, but the xerces-2.8.0 parser does not support the property.
      This leads to the exception attached as "cannot-set-property.txt", which is then "transformed" into the originally described exception.

      Presumably there should be a try-catch surrounding the setProperty to support parsers that do not know the XMLConstants.ACCESS_EXTERNAL_DTD property.

      A binary test case and its sources is attached as testcase.zip. To reproduce:
      1. unpack, go to the bin directory
      2. run the test case as:
      java -Djavax.xml.accessExternalDTD=all -Djavax.xml.accessExternalSchema=all -Djavax.xml.accessExternalStylesheet=all -jar transform-test.jar

      This should lead to the exception attached as "transformation-exception.txt" when running on:
      $ java -version
      java version "1.8.0-ea"
      Java(TM) SE Runtime Environment (build 1.8.0-ea-b91)
      Java HotSpot(TM) 64-Bit Server VM (build 25.0-b33, mixed mode)

            joehw Joe Wang
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: