Re: Locator info for a net.sf.saxon.trans.DynamicError

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Locator info for a net.sf.saxon.trans.DynamicError

Christian Roth-4
Michael Kay wrote on April 28, 2005:

>If you want to fix this in the source, change the endDocument() method of
>net.sf.saxon.TransformerHandlerImpl to read:
>
>    public void endDocument() throws SAXException {
>        super.endDocument();
>        DocumentInfo doc = (DocumentInfo)builder.getCurrentRoot();
>        if (doc==null) {
>            throw new SAXException("No source document has been built");
>        }
>        doc.getNamePool().allocateDocumentNumber(doc);
>        try {
>            controller.transformDocument(doc, result);
>        } catch (TransformerException err) {
>            if (err instanceof XPathException &&
>!((XPathException)err).hasBeenReported()) {
>                try {
>                    controller.getErrorListener().fatalError(err);
>                } catch (TransformerException e) {
>                    //
>                }
>            }
>            throw new SAXException(err);
>        }
>    }

Sorry for coming back to this. I just investigated updating from Saxon
8.4 to 8.5.1 and checked which of the patches that I applied myself are
now already included with Saxon, and I stumbled upon the following issue
again.

As mentioned earlier on this list (April), I think this code might still
have a bug. My own patched method reads like this:

    public void endDocument() throws SAXException {
        super.endDocument();
        DocumentInfo doc = (DocumentInfo)builder.getCurrentRoot();
        if (doc==null) {
            throw new SAXException("No source document has been built");
        }
        doc.getNamePool().allocateDocumentNumber(doc);
        try {
            controller.transformDocument(doc, result);
        } catch (TransformerException err) {
            if (err instanceof XPathException &&
                !((XPathException)err).hasBeenReported()) {
                try {
                    controller.getErrorListener().fatalError(err);
                } catch (TransformerException e) {
                    throw new SAXException( err ); // <*********** +CR
                }
                return; // <************************************** +CR
            }
            throw new SAXException(err);
        }
    }

My reasoning is that when an uncaught TransformerException occurs and
bubbles up to endDocument(), it will be reported to an installed
ErrorListener via its fatalError() method. Currently, even after
successfully reporting it, the code still throws the original err object
anyway. The javax.xml.transform.ErrorListener interface documentation states:

"For transformation errors, a Transformer must use this interface
instead of throwing an exception: it is up to the application  to
decide whether to throw an exception for different types of  errors and
warnings."

Shouldn't the code *not* throw the err object after reporting it
successfully to the installed ErrorListener? This is the behaviour I try
to achieve by the two code modifications above - throw only when
delivery to the ErrorListener fails.

Regards, Christian.



-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Locator info for a net.sf.saxon.trans.DynamicError

Michael Kay
I'm more concerned that a TransformerHandler should obey the general
contract for a ContentHandler; I think code in a processing pipeline that
invokes a ContentHandler has a right to expect that if a method such as
endDocument() doesn't succeed then it will throw an exception. I think that
pipeline-based applications could break if this isn't the case. One can't
expect that the ErrorListener will be able to communicate to the client of
the ContentHandler that the transformation has failed (certainly the
standard error listener won't be able to).

Michael Kay
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Christian Roth
> Sent: 26 October 2005 17:35
> To: Saxon-Help Mailing List
> Subject: Re: [saxon] Locator info for a
> net.sf.saxon.trans.DynamicError
>
> Michael Kay wrote on April 28, 2005:
>
> >If you want to fix this in the source, change the
> endDocument() method of
> >net.sf.saxon.TransformerHandlerImpl to read:
> >
> >    public void endDocument() throws SAXException {
> >        super.endDocument();
> >        DocumentInfo doc = (DocumentInfo)builder.getCurrentRoot();
> >        if (doc==null) {
> >            throw new SAXException("No source document has
> been built");
> >        }
> >        doc.getNamePool().allocateDocumentNumber(doc);
> >        try {
> >            controller.transformDocument(doc, result);
> >        } catch (TransformerException err) {
> >            if (err instanceof XPathException &&
> >!((XPathException)err).hasBeenReported()) {
> >                try {
> >                    controller.getErrorListener().fatalError(err);
> >                } catch (TransformerException e) {
> >                    //
> >                }
> >            }
> >            throw new SAXException(err);
> >        }
> >    }
>
> Sorry for coming back to this. I just investigated updating from Saxon
> 8.4 to 8.5.1 and checked which of the patches that I applied
> myself are
> now already included with Saxon, and I stumbled upon the
> following issue
> again.
>
> As mentioned earlier on this list (April), I think this code
> might still
> have a bug. My own patched method reads like this:
>
>     public void endDocument() throws SAXException {
>         super.endDocument();
>         DocumentInfo doc = (DocumentInfo)builder.getCurrentRoot();
>         if (doc==null) {
>             throw new SAXException("No source document has
> been built");
>         }
>         doc.getNamePool().allocateDocumentNumber(doc);
>         try {
>             controller.transformDocument(doc, result);
>         } catch (TransformerException err) {
>             if (err instanceof XPathException &&
>                 !((XPathException)err).hasBeenReported()) {
>                 try {
>                     controller.getErrorListener().fatalError(err);
>                 } catch (TransformerException e) {
>                     throw new SAXException( err ); // <*********** +CR
>                 }
>                 return; // <************************************** +CR
>             }
>             throw new SAXException(err);
>         }
>     }
>
> My reasoning is that when an uncaught TransformerException occurs and
> bubbles up to endDocument(), it will be reported to an installed
> ErrorListener via its fatalError() method. Currently, even after
> successfully reporting it, the code still throws the original
> err object
> anyway. The javax.xml.transform.ErrorListener interface
> documentation states:
>
> "For transformation errors, a Transformer must use this interface
> instead of throwing an exception: it is up to the application  to
> decide whether to throw an exception for different types of  
> errors and
> warnings."
>
> Shouldn't the code *not* throw the err object after reporting it
> successfully to the installed ErrorListener? This is the
> behaviour I try
> to achieve by the two code modifications above - throw only when
> delivery to the ErrorListener fails.
>
> Regards, Christian.
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.
> Get Certified Today * Register for a JBoss Training Course
> Free Certification Exam for All Training Attendees Through End of 2005
> Visit http://www.jboss.com/services/certification for more information
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>





-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Locator info for a net.sf.saxon.trans.DynamicError

Christian Roth-4
Michael Kay wrote:

>One can't
>expect that the ErrorListener will be able to communicate to the client of
>the ContentHandler that the transformation has failed (certainly the
>standard error listener won't be able to).

It can - by simply (re-)throwing the exception. To the client, this
looks exactly like endDocument() threw (at least as done in my suggested
patch).

I see that there's a difference in behaviour between the default
ErrorHandler in the default ContentHandler implementation, which by
default does throw an exception:

<http://xml.apache.org/xalan-j/apidocs/org/xml/sax/helpers/
DefaultHandler.html#fatalError(org.xml.sax.SAXParseException)>

and the specification for the default ErrorListener, which is said to be
throwing no exceptions at all:

<http://xml.apache.org/xalan-j/apidocs/javax/xml/transform/ErrorListener.html>

I think this is unfortunate. The default ErrorListener.fatalError()
implementation should throw, and from the documentation, Xalan's default
implementation seems to actually do this).

Anyway, this is no longer a Saxon issue, of course. Thanks for the
pointer to the ErrorListener's default behaviour spec - I didn't know this.

Regards, Christian.




-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help