Bug #4993


java.lang.IllegalStateException: Prefix is bound to the wrong namespace {}

Added by Philip Fearon almost 3 years ago. Updated over 2 years ago.

Start date:
Due date:
% Done:


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


This exception is thrown in Saxon 10.5 by an XSLT transform deep within our product's Java filter-chain class. The XML source file ([00-2]-dxml-whitespaceDetection.xml) for the transform (attached) has a root element in the default namespace (i.e. with no prefix).

I'm afraid I can't reproduce this exception yet in a simple test case outside our own products XSLT pipeline infrastructure.

Running the same transform from the command-line or a simplified Java Saxon API test does not reproduce the issue.

The full stack trace (when running testng) is shown at the end. The input file to the transform is attached.

A simplified version of the stylesheet that still throws the exception is shown below. Note that replacing the xsl:copy-of instruction and uncommenting the xsl:apply-templates instruction that is on the following line seems to be a viable workaround.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=""
  <xsl:mode on-no-match="shallow-copy"/>
  <xsl:template match="/*">
      <xsl:copy-of select="node()"/>
      <!-- <xsl:apply-templates select="node()"/> -->

Some additional context: We're in the process of adding Saxon 10.n compatibility to our Java project that currently supports Saxon 9.8 and 9.9. This problem appears in a number of our regression tests when run with Saxon 10.5, the same exception is not thrown with Saxon 9.8 or Saxon 9.9 versions. Here's the stack trace:

java.lang.RuntimeException: Internal error evaluating template rule  at line 8 in module file:/Users/philipf/dev/core/test/resources/xsl/formatting/rename-formatting.xsl
 at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(
 at net.sf.saxon.trans.Mode.applyTemplates(
 at net.sf.saxon.trans.rules.ShallowCopyRuleSet.process(
 at net.sf.saxon.trans.Mode.applyTemplates(
 at net.sf.saxon.trans.XsltController.applyTemplates(
 at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(
 at net.sf.saxon.s9api.XsltTransformer.transform(
	at com.deltaxml.cores9api.XsltStep.internalRunStep(
	at com.deltaxml.cores9api.RunnableFilterChain.runFilterChain(
	at com.deltaxml.cores9api.RunnableFilterChain.runFilterChain(
	at com.deltaxml.cores9api.PipelinedComparatorS9$
	at com.deltaxml.cores9api.PipelinedComparatorS9.compareXdmNode(
	at com.deltaxml.cores9api.IgnorableWsPreservationTest.runSelectiveTestComparison(
	at com.deltaxml.cores9api.IgnorableWsPreservationTest.testIgnorableWsContent(
 at org.testng.internal.MethodInvocationHelper.invokeMethod(
 at org.testng.internal.Invoker.invokeMethod(
 at org.testng.internal.Invoker.invokeTestMethod(
 at org.testng.internal.Invoker.invokeTestMethods(
 at org.testng.internal.TestMethodWorker.invokeTestMethods(
 at org.testng.TestRunner.privateRun(
 at org.testng.SuiteRunner.runTest(
 at org.testng.SuiteRunner.runSequentially(
 at org.testng.SuiteRunner.privateRun(
 at org.testng.SuiteRunnerWorker.runSuite(
 at org.testng.TestNG.runSuitesSequentially(
 at org.testng.TestNG.runSuitesLocally(
 at org.testng.TestNG.runSuites(
 at org.testng.TestNG.privateMain(
 at org.testng.TestNG.main(
Caused by: java.lang.IllegalStateException: Prefix  is bound to the wrong namespace {}
 at net.sf.saxon.event.RegularSequenceChecker.startElement(
 at net.sf.saxon.event.ComplexContentOutputter.startElement(
 at net.sf.saxon.tree.tiny.TinyElementImpl.copy(
 at net.sf.saxon.expr.instruct.CopyOf.copyOneNode(
 at net.sf.saxon.expr.instruct.CopyOf.lambda$processLeavingTail$1(
 at net.sf.saxon.expr.instruct.CopyOf.processLeavingTail(
 at net.sf.saxon.expr.instruct.Instruction.process(
 at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(
 at net.sf.saxon.expr.instruct.Copy.processLeavingTail(
 at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(
 ... 42 more


[00-2]-dxml-whitespaceDetection.xml (1.08 KB) [00-2]-dxml-whitespaceDetection.xml Philip Fearon, 2021-05-18 13:12
rename-formatting.xsl (417 Bytes) rename-formatting.xsl Philip Fearon, 2021-05-18 13:12
Actions #1

Updated by Michael Kay almost 3 years ago

Thanks for reporting.

The error is detected in the RegularSequenceChecker which sits between the XSLT engine and its output pipeline (usually a serializer) and checks that the sequence of events passed down the pipeline is consistent. The intent is that the RegularSequenceChecker is present in the pipeline only when Java assertions are enabled, so you may be able to bypass the checks by removing the -ea switch.

The particular message indicates a startElement event with an element name having no prefix, when the NamespaceMap on the same event indicates that the empty prefix is bound to a different namespace. This certainly is something that shouldn't happen, though it's entirely likely that if we didn't check for it (which in earlier releases we didn't), no one would ever notice a problem.

The TinyElement.copy() code that generated this startElement() event mentions bug #2209.

Actions #2

Updated by Philip Fearon almost 3 years ago

OK thanks, with your comment on the -ea switch, I understand better now why I couldn't reproduce this error outside of our TestNG environment.

Our main objective is to ensure the tests pass with Saxon 10.n. I don't yet know quite how our preceding XSLT transform in the pipeline is managing to produce a startElement with no namespaceURI. I'm hoping we can find a workaround using xsl:apply-templates instead of xsl:copy-of

Actions #3

Updated by Michael Kay almost 3 years ago

I'm wondering if the inconsistency might already be present in the source document to the transform. How do you pass documents between stages of the pipeline (lexical XML, event sequence, or node tree)? If it's in the form of a TinyTree, then capturing the structure using TinyTree.diagnosticDump() might yield insights.

Actions #4

Updated by Philip Fearon almost 3 years ago

I'm checking for an inconsistency at the moment. For parsing the lexical XML, we extend org.xml.sax.helpers.XMLFilterImpl to gather lexical information that would otherwise be discarded by the parser. We are seeing another test failure (that passes with Saxon 9.8/9.9) that just might be related to this issue (and may prove easier to analyse).

In this other case, with Saxon 10.5 we're losing the namespace (the same as in this case of an XML attribute - not present in the input XML but present solely because its defined in the XML Schema as a default attribute with a default value.

For info, the XML below is the Saxon 9.8 output from what I believe is our first XSLT filter following the parser:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns:deltaxml="" xmlns:preserve="" xmlns:er="" xmlns:pi="" xmlns:xsi=""
  xmlns:_2="http://com.deltaxml.test/namespace" xsi:noNamespaceSchemaLocation="mini-xhtml-default-att.xsd" _2:test="yes" preserve:defaultAttributes="{http://com.deltaxml.test/namespace}test" preserve:grammar="schema">
  <preserve:xmldecl xml-version="1.0" encoding="UTF-8"/>
    <title>hello world</title>

The output from Saxon 10.5 is:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns:deltaxml="" xmlns:er="" xmlns:pi="" xmlns:preserve="" xmlns:xsi=""
  xsi:noNamespaceSchemaLocation="mini-xhtml-default-att.xsd" test="yes" preserve:defaultAttributes="{http://com.deltaxml.test/namespace}test" preserve:grammar="schema">
  <preserve:xmldecl xml-version="1.0" encoding="UTF-8"/>
    <title>hello world</title>

So, the significant difference is that Saxon 10.5 the attribute named test is in the null namespace rather than the http://com.deltaxml.test/namespace namespace in the 9.8 result that is bound to the _2 prefix.

I'll report back when I have looked at this in more details - the two cases may not be directly related.

Actions #5

Updated by Michael Kay almost 3 years ago

My guess is that this is the same problem as #4996, caused by Xerces failing to declare a namespace (or prefix) when it injects a default attribute whose name is namespaces, as a result of Xerces schema validation.

I've run the test case for bug #4996 on Saxon 9.8, and confirmed that it only works because of namespace fixup on the output pipeline; the inconsistent attribute (with a URI but no prefix) is accepted in the SAX input and stored "as is" in the TinyTree, where the consequences of the inconsistency are rather unpredictable.

I'd suggest that if we can't pin it down to a repro, we close this. Alternatively we could try building a version of 10.x with the patch in and trying that on your workload.

Actions #6

Updated by Michael Kay over 2 years ago

  • Status changed from New to Duplicate
  • Assignee set to Michael Kay

I think the evidence suggests that this has the same root cause as bug #4996, and the patch for #4996 should fix it, even though the symptoms are different.

Please register to edit this issue

Also available in: Atom PDF