limit set by 'FEATURE_SECURE_PROCESSING'
Asked Answered
J

5

12

I used my own xlst transformator in java (XSLTTransformator) but transformation is very big and I have got error:

Caused by: javax.xml.transform.TransformerConfigurationException: JAXP0801002: the compiler encountered an XPath expression containing '107' operators that exceeds the '100' limit set by 'FEATURE_SECURE_PROCESSING'.
                at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:990)
                at com.aspp.dms.ruleengine.transformation.TemplatesCache.retrieveUncached(TemplatesCache.java:44)
                at com.aspp.dms.ruleengine.transformation.TemplatesCache.retrieveUncached(TemplatesCache.java:21)
                at com.gratex.java.util.SoftValueCache.get(SoftValueCache.java:41)
                at com.aspp.dms.ruleengine.transformation.XSLTTransformator.transform(XSLTTransformator.java:73)

Can you please help me find correct argument for java to solve my problem? Something like -DxpathOperatorsLimit=150

thank you

Jori answered 27/5, 2022 at 6:10 Comment(1)
Welcome to StackOverflow! Does it help if you set the feature XMLConstants.FEATURE_SECURE_PROCESSING to false?Fiberglass
J
10

That behaviour seems to come from new FEATURE_SECURE_PROCESSING, which Oracle introduced in a recent "update" of their Java. See: https://www.oracle.com/java/technologies/javase/11-0-15-relnotes.html

It is 3 parameters they introduced:

  1. jdk.xml.xpathExprGrpLimit Description: Limits the number of groups an XPath expression can contain. Default 10.
  2. jdk.xml.xpathExprOpLimit Description: Limits the number of operators an XPath expression can contain. Default 100.
  3. jdk.xml.xpathTotalOpLimit Description: Limits the total number of XPath operators in an XSL Stylesheet. Default 10000.

Your problem is on #2 (JAXP0801002, default 100). We got a very similar issue on #3 (JAXP0801003, default 10.000), with this message (quoted, so google will find it):

ERROR:  'JAXP0801003: the compiler encountered XPath expressions with an accumulated '10.002' operators that exceeds the '10.000' limit set by 'FEATURE_SECURE_PROCESSING'.'
FATAL ERROR:  'JAXP0801003: the compiler encountered XPath expressions with an accumulated '10.002' operators that exceeds the '10.000' limit set by 'FEATURE_SECURE_PROCESSING'.'

We wasted 2 days in getting away of that sh*t.

We added some parameters to the java call:

    java -Djdk.xml.xpathExprGrpLimit=0 -Djdk.xml.xpathExprOpLimit=0 -Djdk.xml.xpathTotalOpLimit=0 -Xmx2g -Xms512m -XX:-UseGCOverheadLimit ....

Parameters 1,2,3 to to solve the issue. Values "0" set the limits to "off". As XPath can now get huge, it might be advisable to set the heap and stack size and change behaviour of the garbage collection (parameters 4-6).

I hope it will help you too. Have fun!

Jacey answered 1/7, 2022 at 18:34 Comment(0)
P
0

If you are running into this problem on MacBook M1 or newer. Try a compatible jdk version from either amazon corretto or zulu. I had to try multiple versions for it to work but specifically 8.275. https://www.azul.com/downloads/?version=java-8-lts&os=macos&architecture=arm-64-bit&package=jdk&show-old-builds=true

Hope this helps!

Pantagruel answered 15/9, 2022 at 16:44 Comment(0)
D
0

Rahul Meena -Djdk.xml.xpathExprGrpLimit=0 -Djdk.xml.xpathExprOpLimit=0 -Djdk.xml.xpathTotalOpLimit=0

Put 3 steps in your restart files.

Despondent answered 16/9, 2022 at 6:23 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Padgett
M
0

I encounter this error in my M1 mbp with Oracle OpenJDK17. It also occurs when running in product env that is based on OpenJDK17 and centos.

This answer surely helps me. But I can not modify all JVM configurations in our product cluster.

So I just set these three parameters using Java code:

System.setProperty("jdk.xml.xpathExprGrpLimit", "0");
System.setProperty("jdk.xml.xpathExprOpLimit", "0");
System.setProperty("jdk.xml.xpathTotalOpLimit", "0");

Notice: Set these parameters before TransformerFactory initialization.

Menander answered 16/2, 2023 at 14:46 Comment(0)
B
0

Thanks to @Ingo Wilkening for providing a solution that worked effectively for me. If your application is running on the Tomcat web server,

Locate the catalina.sh script in your Tomcat installation directory. You can use the find command as follows:

find /path/to/tomcat -name catalina.sh

Once you have found the catalina.sh file, open it in a text editor. You can use the vi editor,

vi /path/to/tomcat/bin/catalina.sh

Within the catalina.sh file, look for the section where Java options (JAVA_OPTS) are typically set. Add the following lines to set the desired Java system properties:

JAVA_OPTS="$JAVA_OPTS -Djdk.xml.xpathExprGrpLimit=0 -Djdk.xml.xpathExprOpLimit=0 -Djdk.xml.xpathTotalOpLimit=0"

Save the changes and restart tomcat.

Book answered 6/7, 2023 at 15:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.