eclipse-birt/birt

BIRT Version >= 4.8 DOCX Export: NullPointerException Caused by Overflow Hidden Enhancement

Closed this issue · 6 comments

Hi Team,

I am exporting a DOCX file using BIRT version 4.8. The DOCX generation utilizes the AbstractWordXmlWriter.java class. During this process, an issue arises due to the enhancement of the overflow hidden property on a table cell in DOCX (see enhancement #369). This leads to a NullPointerException because the method attempts to get the length of a text field, which may potentially be NULL.

When exporting a DOCX file using BIRT version 4.6, it works fine because that enhancement is not present. In that version, it directly calls the AbstractWordXmlWriter.java > writeString(txt, style) method, which handles null values properly.

The enhancement code in cropOverflowString() was added before the writeString(txt, style) method (which is also called from writeTextInRun()). This enhancement methods does not include a NULL check for the text field.

Explanation of How NULL Can Occur:
In the AbstractWordXmlWriter.java class, the writeText() method handles a txt field that can be NULL. If txt is NULL, it calls the writeContent() method in DocWriter.java, passing the NULL value as a parameter. This, in turn, calls the writeTextInRun() method in AbstractWordXmlWriter.java, which also takes the txt parameter.

Inside this method, if the overflow hidden property is set, it calls cropOverflowString(), passing txt as the text parameter. In the cropOverflowString() method, there is a line that initializes a StringBuilder:
StringBuilder sb = new StringBuilder(text.length() + 1);
Here, text.length() is called when txt is NULL, resulting in a NullPointerException.

The latest version of BIRT also contains the same code.

Please find the stacktrace below:
Cause: java.lang.NullPointerException at org.eclipse.birt.report.engine.emitter.wpml.writer.AbstractWordXmlWriter.cropOverflowString(AbstractWordXmlWriter.java:1204) at org.eclipse.birt.report.engine.emitter.wpml.writer.AbstractWordXmlWriter.writeTextInRun(AbstractWordXmlWriter.java:1166) at org.eclipse.birt.report.engine.emitter.wpml.writer.AbstractWordXmlWriter.writeTextInParagraph(AbstractWordXmlWriter.java:1077) at org.eclipse.birt.report.engine.emitter.wpml.writer.AbstractWordXmlWriter.writeText(AbstractWordXmlWriter.java:1094) at org.eclipse.birt.report.engine.emitter.wpml.writer.DocWriter.writeContent(DocWriter.java:272) at org.eclipse.birt.report.engine.emitter.wpml.AbstractEmitterImpl.writeText(AbstractEmitterImpl.java:1035) at org.eclipse.birt.report.engine.emitter.wpml.DocEmitterImpl.writeContent(DocEmitterImpl.java:258) at org.eclipse.birt.report.engine.emitter.wpml.AbstractEmitterImpl.startText(AbstractEmitterImpl.java:411) at org.eclipse.birt.report.engine.emitter.wpml.DocEmitter.startText(DocEmitter.java:397) at org.eclipse.birt.report.engine.presentation.ContentEmitterVisitor.visitText(ContentEmitterVisitor.java:117) at org.eclipse.birt.report.engine.content.impl.TextContent.accept(TextContent.java:71) at org.eclipse.birt.report.engine.presentation.ContentEmitterVisitor.visit(ContentEmitterVisitor.java:51) at org.eclipse.birt.report.engine.presentation.ContentEmitterVisitor.visitChildren(ContentEmitterVisitor.java:171) at org.eclipse.birt.report.engine.presentation.ContentEmitterVisitor.visitCell(ContentEmitterVisitor.java:109) at org.eclipse.birt.report.engine.content.impl.CellContent.accept(CellContent.java:215) at org.eclipse.birt.report.engine.presentation.ContentEmitterVisitor.visit(ContentEmitterVisitor.java:51) at org.eclipse.birt.report.engine.presentation.ContentEmitterVisitor.visitChildren(ContentEmitterVisitor.java:171) at org.eclipse.birt.report.engine.presentation.ContentEmitterVisitor.visitRow(ContentEmitterVisitor.java:100) at org.eclipse.birt.report.engine.content.impl.RowContent.accept(RowContent.java:69)

You've done quite a bit of analysis. You should consider providing a pull request to fix the problem:

https://github.com/eclipse-birt/birt#create-a-birt-development-environment

Failing that, someone is going to ask you for a report, that can be used to reproduce the problem by someone who does not have access to your actual data sources.

@merks We are using BIRT 4.8 version. So can I request a pull for BIRT Version 4.8?

If I resolve the issue in my local environment what should be the next step? How could I use the updated library (Version 4.8) as a supplier in build?

Sorry, no, there are no maintenance builds. All changes must target the master branch and will be built as part of the subsequent release, currently 4.18.

Could you please add a small text-case report with the exception without external dependencies.
So it is possible to use the same report for the fix.

@kamlesh302
I confirm the answer from Ed, your analysis is very good. I created a PR to solve the problem for BIRT 4.18.
But it would helpful to have a kind of test report from your side to see if there are further problems with NPE based on the text-null-value.

I close the issue and with BIRT 4.18 the problem is solved.
If you cn provide the requested demo report we are able to retest the NPE to improve further the NPE-handling there.