Project

Profile

Help

Bug #6464

open

Saxon prints stack trace to console

Added by Lars Marius Garshol 13 days ago. Updated 6 days ago.

Status:
New
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2024-07-03
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

Let's say I make the following minimal Java program, which throws a RuntimeException whenever there is an xsl:message:

package com.realtaonline.render.utils;

import java.io.File;

import javax.xml.transform.SourceLocator;
import javax.xml.transform.stream.StreamSource;
import net.sf.saxon.s9api.MessageListener2;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer;

public class Transformer {

  public static void main(String[] args) throws Exception {
    Processor proc = new Processor(true);
    XsltCompiler compiler = proc.newXsltCompiler();

    RealtaMessageListener listener = new RealtaMessageListener();
    StreamSource ssource = new StreamSource(new File(args[0]));
    XsltExecutable executable = compiler.compile(ssource);
    XsltTransformer transformer = executable.load();

    transformer.setMessageListener(listener);

    transformer.setSource(new StreamSource(new File(args[1])));
    transformer.setDestination(proc.newSerializer(new File(args[2])));
    try {
      transformer.transform();
    } catch (RuntimeException e) {
      System.out.println("We caught the exception, nothing to see here");
    }
  }

  public static class RealtaMessageListener implements MessageListener2 {
    public void message​(XdmNode content, QName errorCode, boolean terminate,
                        SourceLocator locator) {
      throw new RuntimeException("Transform aborted by xsl:message #1");
    }
  }
}

As you see, we catch the RuntimeException at the top level, so the only output should be the line saying we caught it.

However, if I run that with this XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  <xsl:template match="/">
    <xsl:message terminate="true">
      Whoooo
    </xsl:message>
  </xsl:template>
</xsl:stylesheet>

the output I get is:

MacBook-Pro-3:java larsga$ java -cp xmlserver/target/xmlserver-1.0-SNAPSHOT-jar-with-dependencies.jar com.realtaonline.render.utils.Transformer ~/tmp/tst.xsl ~/tmp/tst.xsl ~/tmp/out.xml
java.lang.RuntimeException: Transform aborted by xsl:message #1
	at com.realtaonline.render.utils.Transformer$RealtaMessageListener.message(Transformer.java:44)
	at net.sf.saxon.s9api.AbstractXsltTransformer.lambda$setMessageListener$0(AbstractXsltTransformer.java:305)
	at net.sf.saxon.expr.instruct.MessageInstr$MessageInstrElaborator.lambda$elaborateForPush$0(MessageInstr.java:351)
	at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:376)
	at net.sf.saxon.trans.Mode.handleRuleNotNull(Mode.java:587)
	at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:521)
	at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:684)
	at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:430)
	at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:358)
	at com.realtaonline.render.utils.Transformer.main(Transformer.java:33)
We caught the exception, nothing to see here

So clearly Saxon is printing the stack trace when it catches the exception, before passing it on.

These stack traces appear in our consoles and logs and confuse people into thinking there actually is something wrong in cases where there isn't. It would be great if you could fix this.

Please register to edit this issue

Also available in: Atom PDF