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

Free Support Forum - aspose.com

ReportingEngine.buildReport throws java.lang.ExceptionInInitializerError while inserting Document

I am using aspose.words for java 17.11

I am running into an issue when trying to insert a document using the <<doc[]>> tag. It is always throwing the error

java.lang.IllegalStateException: Tag 'doc' is not well-formed. An expression providing document data should return a byte array, a string, or an instance of type 'class asposewobfuscated.zz7P' or 'class com.aspose.words.Document'.


  • We are using LINQ.
  • I am running multiple documents through the LINQ parsing engine then compiling them into a final combined document. This final combination is where I am running into issues.
  • I have the Aspose.Words.Document element in a wrapper class holding the document type
    (Internal type for sorting. not docx or pdf type)

I have tried storing the document as a byte[] and as a Aspose.Word.Document type, the engine throws the same error each time.
I have saved the prepared documents to make sure they are rendering and not corrupted. They look fine. So it does not appear to be a data issue.
At this point my template contains nothing but the <<doc [document.first().getDoc()]>> where document is my aliased name for List < documentWrapper > objects

import com.aspose.words.Document;

public class documentWrapper {
	private String type;
	private Document doc;

	public documentWrapper(String type, Document doc){
		this.type = type;
		this.doc = doc;

	public String getType() {
		return type;

	public Document getDoc() {
		return doc;

Is this a known issue with words? Is there something I should look for in my rendered documents? like inserted documents cannot contain a header or footer? What am I missing to get this to work?aspose-doc-insert.zip (323.2 KB)

Attatched is a small program to represent the issue


Thanks for your inquiry. Please refer to the following article.
Inserting Documents Dynamically

Please make sure that your template syntax is correct in your document. Following code example shows how to insert document dynamically into another document. Hope this helps you.

Document doc = new Document();
Document subDoc = new Document(MyDir + "subdocument.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

builder.writeln("<<[s.getName()]>> says: \"<<[s.getMessage()]>>.\"");
builder.writeln("<<doc [s.getDoc()]>>");

Sender sender = new Sender("LINQ Reporting Engine", "Hello World", subDoc);
ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, sender, "s");

doc.save(MyDir + "out.docx");

public class Sender {
    public Sender(String name, String message, Document subDoc) {
        _name = name;
        _message = message;
        _doc = subDoc;

    public String getName() {
        return _name;

    public String getMessage() {
        return _message;

    public Document getDoc() {
        return _doc;

    private String _name;
    private String _message;
    private Document _doc;

Still the same issue persists. I have updated the question to contain a demo program to represent the problem I am having.


Thanks for sharing the code example. We are investigating this issue and will get back to you soon.


Thanks for your patience. 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-1797. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.


Thanks for your patience. Please use the following syntax in container.docx. Please check the attachment. container.zip (9.6 KB)

<<doc [((documentWrapper)document.first()).getDoc()]>>

Please also add following line of code in your example.


Please use following code example to get the desired output. Hope this helps you.

Document doc = new Document(MyDir + "insert.docx");

ReportingEngine engine = new ReportingEngine();

Employee employee = new Employee("bob", "marley", "singer", 50);
engine.buildReport(doc, new Object[]{employee, new ArrayList<>()},
        new String[]{"employee", "documents"});
engine.buildReport(doc, employee, "employee");

Document container = new Document(MyDir + "container.docx");

java.util.List<documentWrapper> docs = new ArrayList<documentWrapper>();
docs.add(new documentWrapper("policy", doc));

engine.buildReport(container, new Object[]{new Employee(), docs},
        new String[]{"employee", "document"});

container.save(MyDir + "output.docx");

The issues you have found earlier (filed as WORDSJAVA-1797) have been fixed in this Aspose.Words for .NET 18.7 update and this Aspose.Words for Java 18.7 update.

A post was split to a new topic: LINQ reporting engine with JSON Data