NPE while saving doc as HTML

reproduce_bug_mini_anonymized.docx (4.7 MB)

Summary

Document loads successfully but throws NullPointerException when saving to HTML format.

Issue Description

When attempting to save a specific Word document to HTML format, Aspose throws a NullPointerException deep in the internal conversion code. The document loads without issues.

Stack Trace

java.lang.NullPointerException: Cannot load from object array because the return value of "com.aspose.words.zzZgM.zzZB7()" is null
    at com.aspose.words.zzZuB.zzW07(Unknown Source)
    at com.aspose.words.zzZuB.zzXhM(Unknown Source)
    at com.aspose.words.zzZuB.zzW07(Unknown Source)
    at com.aspose.words.zzY4v.zzYIm(Unknown Source)
    at com.aspose.words.zzXkw.zzVQF(Unknown Source)
    at com.aspose.words.zzXkw.visitParagraphStart(Unknown Source)
    at com.aspose.words.Paragraph.acceptStart(Unknown Source)
    at com.aspose.words.CompositeNode.acceptCore(Unknown Source)
    at com.aspose.words.Paragraph.accept(Unknown Source)
    at com.aspose.words.CompositeNode.acceptChildren(Unknown Source)
    at com.aspose.words.CompositeNode.acceptCore(Unknown Source)
    at com.aspose.words.Body.accept(Unknown Source)
    at com.aspose.words.zzXkw.zzZUu(Unknown Source)

How to reproduce

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

import com.aspose.words.Document;
import com.aspose.words.HtmlSaveOptions;
import com.aspose.words.LoadFormat;
import com.aspose.words.LoadOptions;
import com.aspose.words.SaveFormat;

/**
 * Minimal reproduction case for Aspose support
 *
 * Issue: Document loads successfully but times out (with NullPointerException) when saving to HTML
 *
 * Error: java.lang.NullPointerException: Cannot load from object array because the return value of
 * "com.aspose.words.zzZgM.zzZB7()" is null
 */
public class AsposeMinimalReproduction {

	public static void main(String[] args) throws Exception {
		byte[] fileBytes = Files.readAllBytes(Paths.get("reproduce_bug_mini_anonymized.docx"));

		LoadOptions loadOptions = new LoadOptions();
		loadOptions.setLoadFormat(LoadFormat.AUTO);
		loadOptions.setEncoding(StandardCharsets.UTF_8);

		Document doc = new Document(new ByteArrayInputStream(fileBytes), loadOptions);

		HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.HTML);

		saveOptions.setExportListLabels(com.aspose.words.ExportListLabels.BY_HTML_TAGS);
		saveOptions.setExportTocPageNumbers(true);
		saveOptions.setEncoding(java.nio.charset.StandardCharsets.UTF_8);
		saveOptions.setExportImagesAsBase64(true);

		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

		try {
			// Try to save as HTML - this is where the NullPointerException occurs
			doc.save(outputStream, saveOptions);
			System.out.println("SUCCESS: Document saved to HTML successfully!");
			System.out.println("HTML length: " + outputStream.size() + " bytes");
		} catch (Exception e) {
			System.err.println("FAILED: Exception during save:");
			e.printStackTrace();
			throw e;
		}
	}
}

Aspose version tested

        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-words</artifactId>
            <version>25.9</version>
            <classifier>jdk17</classifier>
        </dependency>

@PS-CL

Summary
A NullPointerException is thrown from deep inside Aspose.Words when calling Document.save() with HtmlSaveOptions. The document loads correctly, so the problem occurs during the HTML export phase.

Why it happens
The stack trace shows the exception originates from internal classes such as com.aspose.words.zzZgM.zzZB7(). This pattern matches other reported Aspose.Words NPEs (e.g., when converting DOCX to PDF) and is typically indicative of a library‑level bug that is triggered by a particular document structure or by the export pipeline itself. The exact document element that causes the failure is not identified in the available evidence.

What to do next

  1. Upgrade Aspose.Words – Use the newest version of the library (e.g., 25.10 or later). Many internal NPEs are fixed in subsequent releases.
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>25.10</version> <!-- or the latest available -->
<classifier>jdk17</classifier>
</dependency>
  1. Verify other output formats – Try saving the same Document as PDF, DOCX, or plain text. If those succeed, the issue is specific to the HTML exporter; if they also fail, the problem may be more general.
doc.save("out.pdf"); // PDF
doc.save("out.docx"); // DOCX
  1. Test with minimal HTML options – Disable optional HTML features to see if the crash is related to a particular flag.
HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.HTML);
// Turn off optional features
opts.setExportListLabels(ExportListLabels.NONE);
opts.setExportTocPageNumbers(false);
opts.setExportImagesAsBase64(false);
doc.save(outputStream, opts);

If the save succeeds, re‑enable the options one by one to isolate the problematic setting.
4. Inspect the source DOCX – Look for complex or unusual constructs (nested lists, custom numbering, TOC fields, images with missing data, etc.) that are known to cause exporter issues. Simplify or temporarily remove such parts and retry the save.
5. Contact Aspose support – If the problem persists after upgrading and isolating options, provide Aspose with:

  • The exact Aspose.Words version and JDK you are using.
  • The minimal reproducible DOCX (or the original file if it cannot be reduced).
  • The code snippet that reproduces the NPE.
    This will allow the Aspose engineering team to investigate the internal bug and supply a fix or a specific workaround.

Following these steps should help you determine whether the NPE is caused by a particular document element, an HTML‑export option, or an underlying bug in the Aspose.Words library, and guide you toward a resolution.

:warning: I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.

I just tested with 25.10 (latest at this point) and still got the same issue.

About Contact Aspose support, I thought that it was exactly what I was doing when posting here. The minimal file and the code snippet are exactly what I provided in my first message.

@PS-CL
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-28821

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.