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

Errors are reported to System.err while ErrorListener is registered

XMLWordPrintable

    • tiger
    • generic
    • generic
    • Verified

      Name: eaR10174 Date: 04/02/2002


        Errors are reported to System.err by Transformer with registered ErrorListener during:
        - transforming the invalid xml document by javax.xml.transform.Transformer.transform()
      method (see test1.java below);
        - creating a Transformer object by javax.xml.transform.TransformerFactory methods from
      the invalid source (see test2.java below).
        The javadoc reads:
        
        "public interface ErrorListener

         To provide customized error handling, implement this interface and use the
      setErrorListener method to register an instance of the implmentation with the
      Transformer. The Transformer then reports all errors and warnings through this
      interface.
        If an application does not register an ErrorListener, errors are reported to
      System.err.
        ..."

        This bug is found in jaxp-1.2.0-beta-b12-04_mar_2002 and and appears while running the
      tests of the JAXP 1.2 TCK:

       api/javax_xml/transform/ErrorListener/index.html#FatalError[FatalError001]
       api/javax_xml/transform/Transformer/index.html#Transform[Transform002]
       api/javax_xml/transform/TransformerFactory/index.html#NewTemplates[NewTemplates002]
       api/javax_xml/transform/TransformerFactory/index.html#NewTransformer[NewTransformer003]

        This behaviour of the JAXP RI affects build of the JAXP TCK 1.2 - the messages about
      fatal errors are written to the build log while the tests passed OK.


      ------------------------------------test1.java-----------------------------
      import javax.xml.transform.Transformer;
      import javax.xml.transform.ErrorListener;
      import javax.xml.transform.TransformerFactory;
      import javax.xml.transform.TransformerException;
      import javax.xml.transform.stream.StreamSource;
      import javax.xml.transform.stream.StreamResult;
      import java.io.StringWriter;
      import java.io.StringReader;
      import javax.xml.transform.TransformerConfigurationException;

      public class test1 implements ErrorListener {

          public static void main (String[] args) {
              String xmlData = "<?xml version='1.0'?>";
              try {
                  TransformerFactory tfactory = TransformerFactory.newInstance();
                  Transformer transformer = tfactory.newTransformer();
                  
                  StringReader in = new StringReader(xmlData);
                  StringWriter out = new StringWriter();
                  
                  StreamSource source = new StreamSource(in);
                  StreamResult result = new StreamResult(out);
          
                  ErrorListener errorListener = new test1();
                  transformer.setErrorListener(errorListener);
                  transformer.transform(source, result);
                  
                  System.out.println("TransformerException not thrown");
              } catch (TransformerConfigurationException e) {
                  System.out.println(e.toString());
              } catch (TransformerException e) {
                  System.out.println("OK");
              }
          }

          public void warning(TransformerException exc) throws TransformerException {
              throw exc;
          }

          public void error(TransformerException exc) throws TransformerException {
              throw exc;
          }

          public void fatalError(TransformerException exc)
                  throws TransformerException {
              throw exc;
          }

      }
      ------------------------------------test2.java-----------------------------
      import javax.xml.transform.ErrorListener;
      import javax.xml.transform.TransformerFactory;
      import javax.xml.transform.TransformerException;
      import javax.xml.transform.stream.StreamSource;
      import java.io.StringReader;
      import javax.xml.transform.TransformerConfigurationException;

      public class test2 implements ErrorListener {

          public static void main (String[] args) {
              String xslData = "<?xml version='1.0'?>" +
                               "<xsl:stylesheet" +
                               " xmlns:xsl='http://www.w3.org/1999/XSL/Transform&#39;" +
                               " version='1.0'" +
                               ">" +
                               " <xsl:template match='/'>" +
                               " Hello World! \n" +
                               "</xsl:stylesheet>";
              try {
                  TransformerFactory tfactory = TransformerFactory.newInstance();
                  StringReader in = new StringReader(xslData);
                  StreamSource source = new StreamSource(in);
                  ErrorListener errorListener = new test2();
                  tfactory.setErrorListener(errorListener);
                  tfactory.newTransformer(source);
                  
                  System.out.println("Exception not thrown");
              } catch (TransformerConfigurationException e) {
                  System.out.println("OK");
              }
          }

          public void warning(TransformerException exc) throws TransformerException {
              throw exc;
          }

          public void error(TransformerException exc) throws TransformerException {
              throw exc;
          }

          public void fatalError(TransformerException exc)
                  throws TransformerException {
              throw exc;
          }

      }
      --------------------------------------------------------------------------
      % echo $CLASSPATH
      .:dom.jar:sax.jar:jaxp-api.jar:xalan.jar:xercesImpl.jar:xsltc.jar

      % java -showversion test1
      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      [Fatal Error] :-1:-1: Premature end of file.
      OK

      % java -showversion test2
      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      [Fatal Error] :2:18: The element type "xsl:template" must be terminated by the matching
      end-tag "</xsl:template>".
      OK
      ---------------------------------------------------------------------------

      ======================================================================

            ayadavsunw Arun Yadav (Inactive)
            evgsunw Evg Evg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: