#509 Cycle in expression tree

v8.7.1
closed
5
2014-10-20
2006-04-25
Michael Kay
No

The following exception can occur at run-time:

java.lang.IllegalStateException: Expression tree appears
to contain a cycle

The exact circumstances have not been pinned down, but
it is associated with an xsl:sort element in which one
or more of the sort properties (for example "order" or
"lang") is defined by an attribute value template. In
this situation the type-checking and optimization of
the "select" expression is (unnecessarily) deferred
until the sort is executed, and if this causes the
expression to be modified, this causes run-time
modification of the expression tree which should never
be allowed, if only for reasons of thread-safety.

The source fix is to move the type-checking of the
select expression of xsl:sort to a method that is
always executed at compile time:

(1) delete lines 71-78 from FixedSortKeyDefintion.java
(package net.sf.saxon.sort) which read:

        if (isBackwardsCompatible()) {
            sortKey = new FirstItemExpression(sortKey);
        } else {
            RoleLocator role =
                new

RoleLocator(RoleLocator.INSTRUCTION, "xsl:sort/select",
0, null);
role.setErrorCode("XTTE1020");
sortKey =
CardinalityChecker.makeCardinalityChecker(sortKey,
StaticProperty.ALLOWS_ZERO_OR_ONE, role);
}

(2) change the typeCheck() method of
SortExpression.java (same package) (line 100) to read

public Expression typeCheck(StaticContext env,

ItemType contextItemType) throws XPathException {
select = select.typeCheck(env, contextItemType);
for (int i=0; i<sortKeys.length; i++) {
Expression sortKey = sortKeys[i].getSortKey();
if (env.isInBackwardsCompatibleMode()) {
sortKey = new FirstItemExpression(sortKey);
} else {
RoleLocator role =
new
RoleLocator(RoleLocator.INSTRUCTION, "xsl:sort/select",
0, null);
role.setErrorCode("XTTE1020");
sortKey =
CardinalityChecker.makeCardinalityChecker(sortKey,
StaticProperty.ALLOWS_ZERO_OR_ONE, role);
}
sortKeys[i].setSortKey(sortKey);
if (fixedSortKeys != null) {
fixedSortKeys[i].setSortKey(sortKey);
}
}
return this;
}

Discussion

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

Sign up for the SourceForge newsletter:





No, thanks