NPE for empty inner table

Hi Team,

I’m using Aspose.Words for Java 14.6.

  1. If I’ve an empty inner table, I get NPE while saving the word or pdf document. However, the exception is not seen if the outer table is empty. This seems like a defect.
  2. The error details are not user friendly. It just says NPE without any more details.

Thanks,
Kumar

Document doc = new Document();
DocumentBuilder docBuilder = new DocumentBuilder(doc);

Table table = null;
docBuilder.startTable();
docBuilder.insertCell();
docBuilder.write("abc");

docBuilder.startTable();

table = docBuilder.endTable();
// table.remove();
docBuilder.endRow();
table = docBuilder.endTable();

doc.save("C:\test_old.doc");
Exception in thread "main" java.lang.NullPointerException
at com.aspose.words.zzJ5.zzT(Unknown Source)
at com.aspose.words.zzZF2.zzZfE(Unknown Source)

Hi team,

I found a regression (different testcase) from Aspose.Words for Java 14.5.

If there is just one table in the document and if it is empty, word generation goes through in both 14.5 and 14.6.
If there are two independent tables and if one of the table is empty, NPE is seen in 14.6 but the Word/PDF is generated using 14.5.

Scenario 1: Fails in 14.6, works in 14.5
testEmptyTable(docBuilder, false);
testEmptyTable(docBuilder, true);

Scenario 1: Works in both 14.6 and 14.5.
testEmptyTable(docBuilder, false);

Thanks,
Kumar

private static void testEmptyTable(DocumentBuilder docBuilder, boolean writeText) throws Exception
{
    docBuilder.startTable();
    if (writeText)
    {
        docBuilder.insertCell();
        docBuilder.write("abc");
    }
    docBuilder.endTable();
}

Aspose product and version is = Aspose.Words for Java : 14.6.0.0

Exception in thread "main" java.lang.NullPointerException
at com.aspose.words.zzNR.zzW(Unknown Source)
at com.aspose.words.zzNR.visitTableStart(Unknown Source)

Hi Kumar,

Thanks for your inquiry.

I have worked with your shared code and scenarios and have found that the issues you have reported are not bugs. The startTable does not create the table until you call the insertCell method. So, please call the insertCell method after calling startTable method as highlighted code below.

Please let us know if you have any more queries.

private static void testEmptyTable(DocumentBuilder docBuilder, boolean writeText) throws Exception
{
    docBuilder.startTable();
    docBuilder.insertCell();
    if (writeText)
    {
        docBuilder.write("abc");
    }
    docBuilder.endTable();
}
Document doc = new Document();
DocumentBuilder docBuilder = new DocumentBuilder(doc);
Table table = null;
docBuilder.startTable();
docBuilder.insertCell();
docBuilder.writeln("abc");
docBuilder.startTable();
docBuilder.insertCell();
docBuilder.endTable();
// table.remove();
docBuilder.endRow();
docBuilder.endTable();
doc.save(MyDir + "Out.doc");

Hi Tahir,

I got your suggestion. But something that worked in 14.5 and earlier, fails in 14.6. Try the below code.

Thanks,
Kumar

public static void main(String[] args) throws Exception
{
    Utils.setupLicense();
    Utils.printAsposeVersion();

    Document doc = new Document();
    DocumentBuilder docBuilder = new DocumentBuilder(doc);

    testEmptyTable(docBuilder, false);
    testEmptyTable(docBuilder, true);

    doc.save("C:\test_old.doc");

    System.out.println("done");
}

private static void testEmptyTable(DocumentBuilder docBuilder, boolean writeText) throws Exception
{
    docBuilder.startTable();
    if (writeText)
    {
        docBuilder.insertCell();
        docBuilder.write("abc");
    }
    docBuilder.endTable();
}

Hi Kumar,

Thanks for your inquiry. I have tested the scenario and have managed to reproduce the same issue at my side. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-10543. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-10543) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.