MailMerge.getFieldNames throws java.lang.StackOverflowError using Java

We are experiencing a stackoverflowerror when calling MailMerge.getFieldNames() for example.docx in the stackOverflowError Aspose Word.zip (29.4 KB)
attached example project.
We have end-users creating mail merge templates and we do not want to confront them with a stackoverflowerror when they’re doing the actual mailmerge.
Would it be possible for you to investigate this issue?
Many thanks.

Exception in thread "main" java.lang.StackOverflowError
at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:4841)
at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4700)
at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:3927)
at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4736)
at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4791)
at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:4928)
at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:4850)
at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4700)
at java.base/java.util.regex.Pattern$CharProperty.match(Pattern.java:3927)
at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4736)
at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4791)
at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:4928) ....

@JeroenD

We have tested the scenario using the latest version of Aspose.Words for Java 20.2 and have not found the shared issue. So, please use Aspose.Words for Java 20.2.

Thanks for the quick reply. However, I am able to reproduce the error with version 20.2.
I found out that it depends on the configured maximum stack size for the Java process. If I set the stack size to 1MB ( -Xss1m ) I can reproduce this stackoverflowerror.
I cannot imagine it is correct behavior to have a 1MB stack for such a small document like the one attached. Also, in example.docx if the text after the field (which is missing the end } ) is enlarged (example-larger.zip (14.3 KB))the issue can also reproduced with larger stack sizes ( larger then 5MB).

For your convenience follows the bottom of the stacktrace:

...
match:4928, Pattern$Loop (java.util.regex)
match:4850, Pattern$GroupTail (java.util.regex)
match:4700, Pattern$BranchConn (java.util.regex)
match:3927, Pattern$CharProperty (java.util.regex)
match:4736, Pattern$Branch (java.util.regex) [2]
match:4791, Pattern$GroupHead (java.util.regex)
match:4928, Pattern$Loop (java.util.regex)
match:4850, Pattern$GroupTail (java.util.regex)
match:4700, Pattern$BranchConn (java.util.regex)
match:3927, Pattern$CharProperty (java.util.regex)
match:4736, Pattern$Branch (java.util.regex) [1]
match:4791, Pattern$GroupHead (java.util.regex)
matchInit:4953, Pattern$Loop (java.util.regex)
match:4874, Pattern$Prolog (java.util.regex)
match:4791, Pattern$GroupHead (java.util.regex)
match:4099, Pattern$Slice (java.util.regex)
match:3606, Pattern$Start (java.util.regex)
search:1729, Matcher (java.util.regex)
find:746, Matcher (java.util.regex)
<init>:43, zz3O (com.aspose.words.internal)
zzZ:128, zz3M (com.aspose.words.internal)
zzW7:98, zz3M (com.aspose.words.internal)
zzYU:130, zzZZP (com.aspose.words)
zzZsB:52, zzZZP (com.aspose.words)
zzZ:235, Range (com.aspose.words)
zzYsU:57, zzYRE (com.aspose.words)
zzd:40, zzYRE (com.aspose.words)
getFieldNames:536, MailMerge (com.aspose.words)
main:15, Main (com.company)

@JeroenD

Please share the complete steps that you are using to reproduce this issue at our end. Please also share your working environment e.g. operating system, Java version etc.

Please create a simple Java application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing. Thanks for your cooperation.

Simple java application (Intellij project, only add Aspose words lib in the lib folder) and run the main function. stackOverflowError Aspose Word larger example.zip (45.3 KB)

If it cannot be reproduced, make sure the maximum stacksize is set when running the main function, by adding the command line parameter -Xss1m

Operating system: macOS 10.15.2 (19C57) Catalina
java --version
openjdk 11.0.1 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)

@JeroenD

Thanks for sharing the detail. It would be great if you please ZIP and attach your idea.vmoptions file. We will use the same setting as of yours for testing. Thanks for your cooperation.

Here it is. idea.vmoptions.zip (1.0 KB)

Thank you, Jeroen

@JeroenD

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSJAVA-2324. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

1 Like

@JeroenD

Could you please share the answer to following questions for further analysis?

  1. Please share why you need to limit Stack Size specifically.
  2. Please share example document consist from one super big paragraph. Do you have end-users that compose merge templates with 19420 words in the single paragraph?

Thanks for your cooperation.