Project

Profile

Help

Bug #6394

closed

compileLibrary on modules which import a common module causes "Duplicate definition of global variable" exception

Added by Joshua Maurice about 1 month ago. Updated 30 days ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
XQuery Java API
Sprint/Milestone:
-
Start date:
2024-04-15
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

What am I doing? With a single XQueryCompiler object, I call compileLibrary on the following 3 xq library files (three calls to compileLibrary, once per library file).

xquery version "3.0" encoding "utf-8";
module namespace xmlch = "urn:activevos:avsf:xquery:utils:xmlcharutil";
declare variable $xmlch:xmlLetter := "foo";
xquery version "3.0" encoding "utf-8";
module namespace j2x = "urn:informatica:ae:xquery:json2xml";
import module namespace xmlch = "urn:activevos:avsf:xquery:utils:xmlcharutil";
xquery version "3.0" encoding "utf-8";
module namespace util = "urn:activevos:spi:functions:utilities";
import module namespace xmlch = "urn:activevos:avsf:xquery:utils:xmlcharutil";
import module namespace j2x = "urn:informatica:ae:xquery:json2xml";

What do I observe?

Exception in thread "main" net.sf.saxon.s9api.SaxonApiException: Duplicate definition of global variable xmlch:xmlLetter (see line 3 in module urn:activevos:avsf:xquery:utils:xmlcharutil)
	at net.sf.saxon.s9api.XQueryCompiler.compileLibrary(XQueryCompiler.java:559)
	at com.jmaurice.TestSaxonBug.main(TestSaxonBug.java:86)
Caused by: net.sf.saxon.trans.XPathException: Duplicate definition of global variable xmlch:xmlLetter (see line 3 in module urn:activevos:avsf:xquery:utils:xmlcharutil)
	at net.sf.saxon.query.QueryModule.declareVariable(QueryModule.java:814)
	at com.saxonica.expr.QueryLibraryImpl.link(QueryLibraryImpl.java:42)
	at net.sf.saxon.query.XQueryParser.applyModuleImport(XQueryParser.java:1361)
	at net.sf.saxon.query.XQueryParser.processPreamble(XQueryParser.java:969)
	at net.sf.saxon.query.XQueryParser.parseLibraryModule(XQueryParser.java:460)
	at com.saxonica.ee.optim.StaticQueryContextEE.compileLibrary(StaticQueryContextEE.java:160)
	at com.saxonica.ee.optim.StaticQueryContextEE.compileLibrary(StaticQueryContextEE.java:204)
	at net.sf.saxon.s9api.XQueryCompiler.compileLibrary(XQueryCompiler.java:557)
	... 1 more

What do I expect? This should not throw an exception. A single XQueryCompiler object should be able to successfully compile these three xquery libraries with compileLibrary().

Other Details

A full repro (minus the Enterprise Edition license details) is attached as a zip, which includes the 3 xquery xq files and a Java source file for a standalone Java program used to reproduce the buggy behavior.

Found in Saxonica Enterprise Edition, release 11.5.

The bug category is either "XQuery Java API" or "Performance". It might be "Performance" because we can work around this bug by simply not precompiling the libraries with the compileLibrary call.

Note: This appears to be the same issue as: "https://saxonica.plan.io/issues/2429". I have tried with XQUERY_MULTIPLE_MODULE_IMPORTS true and false, and I have tried with various combinations and values of compiler.setBaseURI and StreamSource objects returned from the ModuleURIResolver, but I still get the same error.

PS: My company, Informatica, has developed a workaround, but it is quite complex and involves subclassing two Saxonica internal classes, com.saxonica.expr.QueryLibraryImpl and com.saxonica.ee.optim.StaticQueryContextEE.


Files

repro.zip (2.33 KB) repro.zip Joshua Maurice, 2024-04-15 20:06

Please register to edit this issue

Also available in: Atom PDF