Debug optimization problem

  • Libor

    Libor - 2011-09-27

    I'm using Saxon 9.3 EE and for one of the stylesheets I'm getting this
    compilation error:

      Cause: Attempt to end document in serializer when elements are unclosed
    java.lang.IllegalStateException: Attempt to end document in serializer when elements are unclosed
            at net.sf.saxon.serialize.XMLEmitter.endDocument(
            at net.sf.saxon.event.ProxyReceiver.endDocument(
            at net.sf.saxon.trace.ExpressionPresenter.close(
            at net.sf.saxon.expr.Expression.explain(
            at net.sf.saxon.expr.Optimizer.trace(
            at net.sf.saxon.expr.LetExpression.optimize(
            at net.sf.saxon.expr.ExpressionVisitor.optimize(
            at net.sf.saxon.PreparedStylesheet.setStylesheetDocument(
            at net.sf.saxon.PreparedStylesheet.prepare(
            at net.sf.saxon.TransformerFactoryImpl.newTemplates(
            at com.atypon.literatum.util.xml.TransformerCache.instantiateTemplate(

    I was able to work it around by disabling optimizations
    xformFactory.setAttribute(FeatureKeys.OPTIMIZATION_LEVEL, "0");

    How can I find what is the real problem? What document is being serialized?
    What are those unclosed elements? What steps should I take to debug it?

  • Michael Kay

    Michael Kay - 2011-09-27

    The problem occurs while outputting the optimiser trace messages, so you
    should be able to avoid it by avoiding use of -explain. I would like to have a
    copy of the stylesheet that causes the problem so that I can fix it.

  • Libor

    Libor - 2011-09-28

    Thanks Michael,
    you are right, it has something to do with the
    FeatureKeys.TRACE_OPTIMIZER_DECISIONS set to Boolean.TRUE. We do not use that
    in production, so I re-enabled optimizations and hacked the debug mode to skip
    optimizer decisions tracing for this specific transformation.
    I will try to strip out all java extension calls and get smallest style sheet
    where tracing optimizer decision is still failing.

  • Libor

    Libor - 2011-09-28

    I've done pruning up to this point
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:transform version="2.0" xmlns:xsl="&lt;span&gt;[]&lt;/span&gt; (">

    <xsl:import href="xxx.xsl"/>

    <xsl:template match="foo">
    <xsl:variable name="bar">
    <xsl:value-of select="$bar"/>


    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:transform version="2.0" xmlns:xsl="&lt;span&gt;[]&lt;/span&gt; (">

    <xsl:template match="foo">
    <xsl:value-of select="'x'"/>


    This is still causing the "java.lang.IllegalStateException: Attempt to end
    document in serializer when elements are unclosed" when tracing of optimizer
    decisions is enabled.

  • oneil

    oneil - 2011-09-29


    This problem has already been fixed in the Saxon release version
    Please see the bug ID: 3184807).

    I am not sure which version you are currently running but if you do an upgrade
    to then you should be OK.

  • Libor

    Libor - 2011-09-29

    Thanks, we will try that.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks