Project

Profile

Help

Bug #6186

closed

IndexOutOfBounds exception during stylesheet compilation when package is overridden

Added by Michael Kay over 1 year ago. Updated about 1 year ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
XSLT 3.0 packages
Sprint/Milestone:
-
Start date:
2023-08-25
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
11, 12, trunk
Fix Committed on Branch:
11, 12, trunk
Fixed in Maintenance Release:
Platforms:
.NET, Java

Description

Summary

An IndexOutOfBounds exception occurs with the package dependency graph (TOP->WIF, TOP->IR, IR->WIF), where TOP overrides components in both WIF and IR, including overriding a mode in WIF that is not directly referenced in IR, but exists implicitly in IR as a hidden component.

Original Report

Reported by email:

I get a fatal error during compile time when running my Word conversion tool:

java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266) at java.base/java.util.Objects.checkIndex(Objects.java:361) at java.base/java.util.ArrayList.set(ArrayList.java:441) at net.sf.saxon.style.StylesheetPackage.lambda$addComponentsFromUsedPackage$0(StylesheetPackage.java:729) at net.sf.saxon.style.StylesheetPackage.complete(StylesheetPackage.java:492) at net.sf.saxon.style.PrincipalStylesheetModule.complete(PrincipalStylesheetModule.java:1656) at net.sf.saxon.style.Compilation.compilePackage(Compilation.java:332) at net.sf.saxon.style.StylesheetModule.loadStylesheet(StylesheetModule.java:249) at net.sf.saxon.style.Compilation.compileSingletonPackage(Compilation.java:113) at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:936) at net.sf.saxon.Transform.doTransform(Transform.java:769) at net.sf.saxon.Transform.main(Transform.java:81) Fatal e

Actions #2

Updated by Michael Kay over 1 year ago

Reproduced using the command line options

-xsl:Customization/XSL/ConvertToIR.xsl -nogo -jit:off -lib:Core/XSL/pkg.to-ir.xsl:EDK/Scripts/XSL/WordCore/pkg.to-wif.xsl
Actions #3

Updated by Michael Kay over 1 year ago

Switching StylesheetPackage.TRACING on, the last message before the crash is

Doing mode completion for mode towif:document

The crash occurs because the array for new component bindings has length zero (whereas the old component bindings has length 34).

We're in addComponentsFromUsedPackage - it's a long time since I looked at this rather complex code and it's going to require some refamiliarisation.

Actions #4

Updated by Michael Kay over 1 year ago

We have a freestanding stylesheet module ConvertToIR.xsl with use-package dependencies on both to-wif.xsl and to-ir.xsl, in both cases with overriding declarations.

Package to-ir.xsl itself has a use-package dependency on to-wif.xsl, again with overrides.

I think it's this that is causing the problem. I haven't yet established whether the stylesheet is legal or not; either way, of course, Saxon shouldn't be crashing.

At the time of the failure, the freestanding module is copying in the definition of mode towif:document from package to-ir.xsl, which contains this component only because it acquired it from to-wif.xsl.

Actions #5

Updated by Michael Kay over 1 year ago

The problem goes away if we change line 709 of StylesheetPackage from

if (newC.getActor() instanceof Mode && overrides.contains(name)) {

to

if (newC.getActor() instanceof Mode && overrides.contains(name) && !newC.getVisibility().equals(HIDDEN)) {

The thinking behind this is that we only want to do this special code for a mode that we are overriding directly, we don't want to do it because we are overriding the same mode in a different package.

This needs checking. There may be a better way.

Actions #6

Updated by Michael Kay over 1 year ago

The change appears to cause no test regressions.

Actions #7

Updated by Michael Kay over 1 year ago

After quite a bit of effort, I have managed to reproduce the problem in a simplified unit test (TestPackage/testBug6186) which will make it easier to see exactly why it is failing and to confirm that the solution is sound.

Actions #8

Updated by Michael Kay over 1 year ago

  • Category set to XSLT 3.0 packages
  • Status changed from New to Resolved
  • Priority changed from Low to Normal
  • Applies to branch 11, 12, trunk added
  • Fix Committed on Branch 11, 12, trunk added
  • Platforms .NET, Java added
Actions #9

Updated by Michael Kay over 1 year ago

  • Description updated (diff)
Actions #10

Updated by O'Neil Delpratt about 1 year ago

  • Fixed in Maintenance Release 12.4 added

Bug fix applied in the Saxon 12.4 Maintenance release. Leaving it marked as 'Resolved' until fix applied on Saxon 11.

Please register to edit this issue

Also available in: Atom PDF