Infinite loop while inserting document in builder

package org.example;

import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;
import com.aspose.words.ImportFormatMode;

public class ClauseDocumentService {


    public static void main(String[] args) throws Exception {
        com.aspose.words.License wordLicense = new com.aspose.words.License();
        wordLicense.setLicense(Main.class.getClassLoader().getResourceAsStream("aspose-licence"));
        Document document = new Document("/Users/govind.sharma/Downloads/ICA_Details.docx");

        Document newDocument = new Document();
        DocumentBuilder documentBuilder = new DocumentBuilder(newDocument);


        documentBuilder.insertDocument(document, ImportFormatMode.KEEP_SOURCE_FORMATTING);
        newDocument.save("/Users/govind.sharma/Downloads/ICA_Recitals_1.docx");
        }
    }

Why there is inifinite loop in this simple document, what should be callbacks while inserting document to avoid such issues in future
ICA_Recitals.docx (47.7 KB)

@ashu_agrawal_sirionlabs_com The problem is not reproducible on my side with the latest 26.6 version of Aspose.Words for java. Please try using the latest version and let us know if the problem still persists on your side.

It’s happenning in my local and our production environment with this document on 26.6 word version itself.

This is root cause based on thread dump and heap dump.

The thread is stuck inside Aspose.Words’ StyleCollectionListCollection mutual recursion during a DocumentBuilder.insertDocument() call in AsposeHelper.createMergedClauseDocument (line 713).

The internal obfuscated methods StyleCollection.zznj(), ListCollection.zznj(), Style.zzz0(), NodeImporter.zznj(), etc. are calling each other in a cycle. This is a known Aspose.Words bug pattern that triggers when:

  • A source Word document has circular list-style references (a list style pointing to a style that points back to it), OR
  • A document has deeply nested or malformed styles that Aspose’s style-resolution/import logic cannot terminate on.

When insertDocument tries to import styles from the source document into the target, the NodeImporter resolves styles recursively — and with a circular reference, it never terminates.

@ashu_agrawal_sirionlabs_com I tested the scenario again and still the problem is not reproducible on my side using the latest 26.6 version of Aspose.Words. Then I tested with older versions and the problem is reproducible with 26.3 version. As I can see several document processing hanging problems were resolved in 26.4 version:
https://releases.aspose.com/words/java/release-notes/2026/aspose-words-for-java-26-4-release-notes/
Most likely one of the fixes also resolved the problem with the attached document.
Therefore, please make sure your project is using the latest version.