Skip to content

Error in line deletion in table from odf text document #298

Description

@Boarschti42

Hi,

we have an issue while deleting some lines in an odt document containing tables. The issue: if the table has merged cells (see attachment sample), the deletion of lines containing this merged cells is not possible. If the merged cells are removed, everything works fine.

Error is located here:

java.lang.NullPointerException: Cannot invoke "org.odftoolkit.odfdom.doc.table.OdfTableCell.isCoveredElement()" because "cell" is null
	at org.odftoolkit.odfdom.doc.table.OdfTableRow.removeAllCellsRelationship(OdfTableRow.java:868)
	at org.odftoolkit.odfdom.doc.table.OdfTable.removeRowsByIndex(OdfTable.java:1816)
	at de.rekn.odftest.DeleteLineTest.testDeleteLine(DeleteLineTest.java:20)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Sample code for reproducing this error:

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;

import org.junit.jupiter.api.Test;
import org.odftoolkit.odfdom.doc.OdfTextDocument;
import org.odftoolkit.odfdom.doc.table.OdfTable;

public class DeleteLineTest {

    @Test
    public void testDeleteLineText() throws URISyntaxException, Exception {
        URL resURL = this.getClass().getResource("/odfWriterTest.odt");

        OdfTextDocument document = OdfTextDocument.loadDocument(Path.of(resURL.toURI()).toFile());
        OdfTable pTable = document.getTableList(true).get(0);

        assertDoesNotThrow(() -> pTable.removeRowsByIndex(2, 1));
    }

}

Testfile odfWriterTest.odt

Can you confirm this is a bug? Are there other ways to solve this problem?

Thanks in advance

Boarschti

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingreview wantedFour eyes notice more than two

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions