Project

Profile

Help

Bug #6361

closed

XPath parser continously looping to find Xpath function library in a given custom xpath expression

Added by Manikandan S 2 months ago. Updated 4 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Saxon extensions
Sprint/Milestone:
-
Start date:
2024-02-27
Due date:
% Done:

0%

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

Description

  • I am trying to load a custom library of XPath functions in my project using a custom build jar. However when the function is called to load the XPath functions i get redirected to XPathParser.java class which is present in the package net.sf.saxon.expr.parser, where a function is called - reportMissingFunction which consist of the following loop and it never exits this loop even though it could not find the a particular XPath function.
  • Jar file is located in classpath under JVM_PARAMS, Xpath function is able to find that jar from classPath.
  if (config.getBooleanProperty(Feature.ALLOW_EXTERNAL_FUNCTIONS)) {
            boolean existsWithDifferentArity = false;

            for(int i = 0; i < arguments.length + 5; ++i) {
                if (i != arguments.length) {
                    SymbolicName.F sn = new SymbolicName.F(functionName, i);
                    if (this.env.getFunctionLibrary().isAvailable(sn)) {
                        existsWithDifferentArity = true;
                        break;
                    }
                }
            }

            if (existsWithDifferentArity) {
                sb.append(". The namespace URI and local name are recognized, but the number of arguments is wrong");
            } else {
                supplementary = getMissingFunctionExplanation(functionName, config);
                if (supplementary != null) {
                    sb.append(". ").append(supplementary);
                }
            }
        } else {
            sb.append(". External function calls have been disabled");
        }
  • I do not understand whats going on and my application freezes since it is always stuck in the for-loop.
  • I am expecting either the function to be found and exit the for-loop and continue the normal behavior of my application or some timeout to be set or an error message to be thrown if the XPath functions are not found in that loop.
  • Please let me know your suggestion on how to proceed.
  • I'm using Saxon 10.6 and Xpath 3.0

Note: Here I'm using custom library(External Jar file) which inside the class path contains some Xpath functions, not modified anything on Saxon FunctionLibrary interface.

Stack overflow ticket : https://stackoverflow.com/questions/78001210/xpath-parser-continously-looping-to-find-xpath-function-library-in-a-given-custo?noredirect=1#comment137514388_78001210

Actions #1

Updated by Martin Honnen about 2 months ago

Can you attach a minimal but complete zip of files allowing others to reproduce this? Do you use a library of XPath functions implemented as integrated extension functions? Or as reflexive? Is that Saxon 10 HE or PE/EE? And as you elsewhere mentioned some update from 9.1 to 10, did your library work with 9.1 but fails with 10?

Actions #2

Updated by Michael Kay about 2 months ago

The Saxon code that you have reproduced here is on an error path; Saxon has already discovered that your stylesheet (or query) is calling a function that it cannot find, and at this point it is trying to construct a message containing an explanation of the possible cause of the problem.

I find it hard to think why the code should get stuck in this loop, but it may be more productive to focus on the primary problem of why the function isn't being found in the first place.

The first thing I would do is to run this with the -TJ option (assuming you are running from the command line), which should give better diagnostics about what is going on.

Actions #3

Updated by Manikandan S about 2 months ago

Hi @Martin Honnen, Here dependency which i am using

net.sf.saxon saxon-ee 10.6 ``` I am not checked with 9.1, here issue is directly reproducible in 10.6.
Actions #4

Updated by Manikandan S about 2 months ago

 <dependency>
            <groupId>net.sf.saxon</groupId>
            <artifactId>saxon-ee</artifactId>
            <version>10.6</version>
        </dependency>
Actions #5

Updated by Michael Kay about 2 months ago

We need to understand what function it is trying to find, and why it is failing to find it.

Have you tried collecting the -TJ output as suggested?

Actions #6

Updated by Norm Tovey-Walsh about 2 months ago

I think Mike's suggestion to collect the -TJ output is probably the best thing to do next, but just in passing, you can't get Saxon EE with the artifact description you provided above. If you add the https://maven.saxonica.com/maven repository to your project, then this description will work:

<dependency>
  <groupId>com.saxonica</groupId>
  <artifactId>saxon-EE</artifactId>
  <version>10.6</version>
</dependency>
Actions #7

Updated by Michael Kay about 2 months ago

  • Category set to Saxon extensions
  • Status changed from New to AwaitingInfo
  • Assignee set to Michael Kay
Actions #8

Updated by Manikandan S about 2 months ago

-TJ output:

user001@KOR-V-002NL:~$ java -jar /home/user001/.m2/repository/net/sf/saxon/saxon-ee/10.6/saxon-ee-10.6.jar -s:/home/user001/Documents/input.xml -xsl:/home/user001/Documents/PDFFormat.xsl -TJ > output.json
Looking for function Q{custom.jar}erstellePDFByteArrayMitTextWasserZeichen#6
Trying net.sf.saxon.functions.registry.XSLT30FunctionSet
Trying net.sf.saxon.style.StylesheetFunctionLibrary
Trying net.sf.saxon.functions.FunctionLibraryList
Looking for function Q{custom.jar}erstellePDFByteArrayMitTextWasserZeichen#6
Trying net.sf.saxon.functions.registry.VendorFunctionSetHE
Trying net.sf.saxon.functions.MathFunctionSet
Trying net.sf.saxon.ma.map.MapFunctionSet
Trying net.sf.saxon.ma.arrays.ArrayFunctionSet
Trying net.sf.saxon.functions.registry.ExsltCommonFunctionSet
Function Q{custom.jar}erstellePDFByteArrayMitTextWasserZeichen not found!
Trying net.sf.saxon.functions.registry.ConstructorFunctionLibrary
Trying net.sf.saxon.query.XQueryFunctionLibrary
Trying net.sf.saxon.functions.IntegratedFunctionLibrary
Trying com.saxonica.config.JavaExtensionLibrary
Trying net.sf.saxon.style.StylesheetFunctionLibrary
Function Q{custom.jar}erstellePDFByteArrayMitTextWasserZeichen not found!
Error near {...hiv: Kopie aus XBAV", 300, ...} at char 0 in xsl:value-of/@select on line 4 column 327 of PDFFormat.xsl:
  XPST0017  Cannot find a 6-argument function named
  Q{custom.jar}erstellePDFByteArrayMitTextWasserZeichen()
Errors were reported during stylesheet compilation
user001@KOR-V-002NL:~$ 
Actions #9

Updated by Michael Kay about 2 months ago

That's useful. It tells us which function wasn't found (Q{custom.jar}erstellePDFByteArrayMitTextWasserZeichen#6) and it tells us where Saxon looked for it.

Where did you expect the function to be found? Is this a Java extension function? Are you imagining that Saxon will look for this function within a JAR file at custom.jar? If you want dynamic loading of extension functions, you need the URI to identify the class name (which must be on the classpath), not to identify a JAR file.

It also means I can perhaps try to replicate the secondary failure that occurred when trying to construct diagnostics.

Actions #10

Updated by Manikandan S about 2 months ago

I have added that Jar in class path and its able to identify that namespace, Here i renamed that to custom.jar because its provided by the customer. Yes this is the Java extension function. actually Main class is missing in that Jar. provided Jar is improper one.

Actions #11

Updated by Michael Kay about 2 months ago

  • Status changed from AwaitingInfo to In Progress

In the supplied -TJ output, you are loading the Saxon EE software, but you are running without a license file. I see exactly the same trace output when I do that. Even without seeing the command that you executed, we can tell that it's Saxon-EE software because com.saxonica.config.JavaExtensionLibrary was searched, and we can tell that there is no license file because net.sf.saxon.functions.registry.VendorFunctionSetHE was searched.

I assume that in live operation (and in the conditions where you hit the original problem) you are using Saxon-EE with a license file. Please could you try again to get the -TJ output with the correct configuration that you use in live running.

I can't think of any circumstances in which using a JAR file name rather than a Java class name as the URI would actually work, but I'd still like to get to the bottom of why it failed to produce proper diagnostics.

Actions #12

Updated by Manikandan S about 2 months ago

Hi Michael,

User1@KOR-V-002NL:~$ java -cp /home/User1/.m2/repository/net/sf/saxon/Saxon-HE/11.4/Saxon-HE-11.4.jar net.sf.saxon.Transform -s:/home/User1/Documents/input.xml -xsl:/home/User1/Documents/PDFFormat.xsl -TJ > output.json
Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlresolver/Resolver
	at net.sf.saxon.lib.CatalogResourceResolver.<init>(CatalogResourceResolver.java:46)
	at net.sf.saxon.Configuration.init(Configuration.java:367)
	at net.sf.saxon.Configuration.<init>(Configuration.java:230)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at java.base/java.lang.Class.newInstance(Class.java:584)
	at net.sf.saxon.Configuration.newConfiguration(Configuration.java:246)
	at net.sf.saxon.s9api.Processor.<init>(Processor.java:69)
	at net.sf.saxon.Transform.doTransform(Transform.java:321)
	at net.sf.saxon.Transform.main(Transform.java:81)
Caused by: java.lang.ClassNotFoundException: org.xmlresolver.Resolver
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:527)
	... 12 more
User1@KOR-V-002NL:~$ java -jar /home/User1/.m2/repository/net/sf/saxon/saxon-ee/10.6/saxon-ee-10.6.jar -s:/home/User1/Documents/input.xml -xsl:/home/User1/Documents/PDFFormat.xsl -TJ > output.json
Looking for function Q{app-service-1.3}erstellePDFByteArrayMitTextWasserZeichen#6
Trying net.sf.saxon.functions.registry.XSLT30FunctionSet
Trying net.sf.saxon.style.StylesheetFunctionLibrary
Trying net.sf.saxon.functions.FunctionLibraryList
Looking for function Q{app-service-1.3}erstellePDFByteArrayMitTextWasserZeichen#6
Trying net.sf.saxon.functions.registry.VendorFunctionSetHE
Trying net.sf.saxon.functions.MathFunctionSet
Trying net.sf.saxon.ma.map.MapFunctionSet
Trying net.sf.saxon.ma.arrays.ArrayFunctionSet
Trying net.sf.saxon.functions.registry.ExsltCommonFunctionSet
Function Q{app-service-1.3}erstellePDFByteArrayMitTextWasserZeichen not found!
Trying net.sf.saxon.functions.registry.ConstructorFunctionLibrary
Trying net.sf.saxon.query.XQueryFunctionLibrary
Trying net.sf.saxon.functions.IntegratedFunctionLibrary
Trying com.saxonica.config.JavaExtensionLibrary
Trying net.sf.saxon.style.StylesheetFunctionLibrary
Function Q{app-service-1.3}erstellePDFByteArrayMitTextWasserZeichen not found!
Error near {...hiv: Kopie aus XBAV", 300, ...} at char 0 in xsl:value-of/@select on line 4 column 327 of PDFFormat.xsl:
  XPST0017  Cannot find a 6-argument function named
  Q{app-service-1.3}erstellePDFByteArrayMitTextWasserZeichen()
Errors were reported during stylesheet compilation

I was added Saxon license file in class path but still getting the same error. can you please explain me how to check in -TJ option.

Thanks, Manikandan.

Actions #13

Updated by Michael Kay about 2 months ago

The error in your 11.4 run is because Saxon 11 requires the XmlResolver to be available. Details at

https://www.saxonica.com/documentation11/index.html#!about/installationjava/jarfiles

Normally Saxon will pick up the XmlResolver automatically, provided that it is in the same directory as the main Saxon jar file (specifically, in ../lib/xml-resolver-4.4.3.jar relative to the Saxon jar file). If you move the Saxon jar file without moving the XmlResolver alongside it, you will need to add the XmlResolver to the class path explicitly.

The error in the 10.6 run is because you are looking for an extension function named Q{app-service-1.3}erstellePDFByteArrayMitTextWasserZeichen#6 and Saxon can't find it. If this is a "reflexive" Java extension function then the URI in the function name needs to be in the form java:classname, as described in the documentation at https://www.saxonica.com/documentation10/index.html#!extensibility/functions

Actions #14

Updated by Martin Honnen about 2 months ago

As for your attempt with java -jar java -jar /home/User1/.m2/repository/net/sf/saxon/saxon-ee/10.6/saxon-ee-10.6.jar , if you have your extension functions in some additional jar files, you will need to run with e.g. java -cp java -jar /home/User1/.m2/repository/net/sf/saxon/saxon-ee/10.6/saxon-ee-10.6.jar:/home/Users1/sample1.jar net.sf.saxon.Transform ..., meaning you need to ensure the jar(s) you need are on the classpath.

Actions #15

Updated by Michael Kay 4 days ago

  • Status changed from In Progress to Closed

I'm closing this as we can't make further progress without addidional information. If you can construct a repro that enables us to investigate the problem further, please feel free to reopen in.

Please register to edit this issue

Also available in: Atom PDF