We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Mail merge engine throws IllegalStateException when cleanup options are used using Java

One of our customers using our reporting system that uses Aspose Words is seeing this issue (we are using 10.8.0).


If you have an empty MailMerge region, setting the mail merge cleanup option to REMOVE_EMPTY_PARAGRAPHS causes an error on executing the merge:

java.lang.IllegalStateException: Cannot remove because there is no parent.
at com.aspose.words.Node.remove(Node.java:432)
at com.aspose.words.zg.ZB(MailMergeRegion.java:177)
at com.aspose.words.zg.ZD(MailMergeRegion.java:269)
at com.aspose.words.zg.a(MailMergeRegion.java:70)
at com.aspose.words.MailMerge.executeWithRegions(MailMerge.java:337)

I have reproduced the issue using the attached Java code and example docx.

It is probably possible for us to do some kind of manual searching of the templates and try to remove empty ones (and if this becomes enough of an issue that’s likely what we will have to do) but it seems like it will be an easier fix on your end to add some sort of check on cleaning empty paragraphs that you do not try and remove paragraphs that are already removed.

Please let me know if this is a known issue, and whether or not it is/will be scheduled for an upcoming release. Thank you.

-Dylan Gulick
Jama Software

Hi Dylan,

Please accept my apology for late response. I have tested the scenario and have not found any issue with REMOVE_EMPTY_PARAGRAPHS at my end. Please use the latest version of Aspose.Words for Java 11.0.0 and let us know, If you still face problem. I have noticed that you have not shared the complete code, please share your complete code for investigation purposes.

Here is a self-contained example of the issue, you should just be able to run it (make sure to have the previously attached docx file in the same directory and see in the console output the unexpected illegal state exception.


I tried updating to 11.0.0 and still see the same issue.

Hi Dylan,

I have worked with your code and like to share with you that you are using executeWithRegions method for simple mail merge (mail merge without regions). Please use Execute method instead of executeWithRegions, see the following code snippet.

Please read following documentation links for your kind reference.

http://docs.aspose.com/display/wordsjava/How+to++Execute+Mail+Merge+with+Regions
https://docs.aspose.com/display/wordsjava/How+to+Execute+Mail+Merge#HowtoExecuteMailMerge-HowtoExecuteSimpleMailMerge

try {

wordDoc.getMailMerge().execute(dataSource);//.executeWithRegions(dataSource);

}

catch (IllegalStateException ise) {

System.out.println("ILLEGAL STATE EXCEPTION(EMPTY REGION): " + ise.getMessage());

}

I’m afraid you are incorrect. I am using Mail Merge Regions for actual Mail Merge Region merging, and the same thing cannot be accomplished in my production code with a normal Mail Merge.

This example is very simple, yes, and the same thing here can be changed to work without regions, but that is not the point. The point of this code was to demonstrate to you an issue I am having with Mail Merge Regions. Please trust me that I am using Mail Merge Regions to actually merge regions. Our full reporting code has multiple types of data sources, each with multiple data entries, several with various levels of child data sources, and we use regions to merge that data into tables using a customer-created template. Switching to a simple “.execute(dataSource)” call winds up with leaving the entire region in the document and not merging it at all.

And I am sorry, but the two pieces of documentation you linked me to provide me with no information about why you think I am using executeWithRegions incorrectly. In fact, several entries up in your documentation this page: https://docs.aspose.com/display/wordsjava/About+Mail+Merge#AboutMailMerge-MailMergewithRegionsExplained seems to verify that I am indeed using it correctly. I honestly don’t understand why you would suggest that I am incorrectly using
“executeWithRegions()” and that I should be using “execute()”, because my template
clearly contains “TableStart” and “TableEnd” merge fields, which are
recognized by Aspose as regions.

As I said, the templates we are running this merge against are customer-created, so we cannot always be certain of their contents. We have run into a customer having empty region templates, and so would like Aspose to be able to handle this case gracefully.

I have provided a simple way for you to reproduce the error we are seeing (I have attached an even more simple docx file you can run my provided code against, if you like). When you run the code that I have provided, are you seeing the same error? If so I would reiterate my original question and ask if there is a workaround for this error and whether or not a fix for this issue is/will be scheduled for an upcoming release.

Hi Dylan,


Thanks for your inquiry.

I managed to reproduce the issue on my side. I have linked your request to the appropriate issue. We will inform you as soon as it is resolved.

Thanks,

Great, thank you! Let me know if there’s anything else I can do to help diagnose the issue, or if you need more information.

-Dylan Gulick
Jama Software

Hi Jama,


Thanks for your offer. Just to let you know, this issue has been fixed and it will be available in the next version of Aspose.Words. This will be released at the end of the month (around the 30th).

Thanks,

Hi Adam,

Could you please clarify what you meant as a bug and what will be changed here? According to Aspose documentation starting from v.10.8.0 the option removes now header (TableStart:XXX) and footer (TableEnd:XXX) paragraphs and we have already updated the documents.

Please do not revert the logic back as this breaks the documents which were already changed! I suggest you do not restore the old functionality but to introduce a new flag like "RemoveTableRegionTags" which can handle an apperance logic for start and elements.

Best regards, Evgeniy

Hi Evgeniy,


Thanks for your inquiry.

Actually this fix just involves avoiding the exception thrown when this option is used with an empty region (with no content in between table tags). All existing functionality will stay exactly the same.

Thanks,

The issues you have found earlier (filed as WORDSNET-5912) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.