Dear Aspose
We’re using Aspose.Words for Java for merging fields in word documents.Currently we are using Aspose 18.7. In the result document we want the fields unlinked therefore we’re calling unlinkFields() on Document. But for one document this operation raises excepction -
Exception in thread "main" java.lang.RuntimeException: java.lang.IllegalStateException: Document structure was changed.
at com.aspose.words.FieldCollection$zzZ.hasNext(Unknown Source).
Here is snippet, that causes issues
doc.getMailMerge().execute(new String[0], new Object[0]);
doc.updateFields();
for(Field field : doc.getRange().getFields()) {
if (field.getType() == FieldType.FIELD_MERGE_FIELD || field.getType() == FieldType.FIELD_IF) {
field.unlink();
}
}
Is this expected behavior? I have not found topic or document that mentioned this code as antipattern. Unfortunately I cant share that document.
For me it looks similiar to concurrent modification while traversing a collection