LayoutEnumerator.setCurrent causes NullPointerException for Table object using Java

I am trying to identify the position of tables in word document. I use the following code:

LayoutCollector layoutCollector = new LayoutCollector(asposeDocument);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(asposeDocument);
Object renderObject = layoutCollector.getEntity(asposeNode);
layoutEnumerator.setCurrent(renderObject);
int pageNumber = layoutEnumerator.getPageIndex(); // page number
java.awt.geom.Rectangle2D.Float rect = layoutEnumerator.getRectangle(); // position on the page

If I use this code for paragraphs, it works perfectly. But if asposeNode is Table, it causes the NPE:
java.lang.NullPointerException: value
at com.aspose.words.LayoutEnumerator.setCurrent(Unknown Source)

Is there another way to get table position in document? Example of document: example.zip (26.2 KB)

@skorpusova,

The following code of Aspose.Words for Java API will calculate the Top and Bottom positions of all Tables in your Word document and you can build logic on this code to get the desired output:

Document doc = new Document("C:\\temp\\example\\example.docx");

LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

for (Table table : (Iterable<Table>) doc.getFirstSection().getBody().getChildNodes(NodeType.TABLE, true)) {
    double minTop = 22 * 72;
    double maxBottom = 0;
    for (Node node : (Iterable<Node>) table.getChildNodes(NodeType.ANY, true)) {
        try {
            layoutEnumerator.setCurrent(layoutCollector.getEntity(node));

            if ((layoutEnumerator.getRectangle().getY() + layoutEnumerator.getRectangle().getHeight()) > maxBottom)
                maxBottom = (layoutEnumerator.getRectangle().getY() + layoutEnumerator.getRectangle().getHeight());

            if (layoutEnumerator.getRectangle().getY() < minTop)
                minTop = layoutEnumerator.getRectangle().getY();
        } catch (Exception ex) {
        }
    }

    double pageWidth = ((Section) table.getAncestor(NodeType.SECTION)).getPageSetup().getPageWidth();

    DocumentBuilder builder = new DocumentBuilder(doc);

    builder.moveTo(table.getPreviousSibling()); // just to anchor shape to
    drawLine(builder, minTop, pageWidth, Color.BLUE);

    builder.moveTo(table.getNextSibling());
    drawLine(builder, maxBottom, pageWidth, Color.RED);
}

doc.save("C:\\Temp\\example\\awjava-21.3.docx");

public static void drawLine(DocumentBuilder builder, double top, double width, Color color) throws Exception {
    Shape line = new Shape(builder.getDocument(), ShapeType.LINE);
    line.setStrokeColor(color);
    line.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
    line.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
    line.setWrapType(WrapType.NONE);
    line.setLeft(0);
    line.setTop(top);
    line.setWidth(width);

    builder.insertNode(line);
}