I am using layoutcollector's getstartpageIndex(), getEndPageIndex() for each run in my code when i am running for multiple large file after some time code is struck at getStartPageIndex()

Document doc=new Document(filePath);
LayoutCollector layoutCollector=new LayoutCollector(doc);
NodeCollection nodes=doc.getChildNodes(true);
for(Node node:nodes)
{
 if(node.getType==NodeType.PARAGRAPH)
 {
  Paragraph paragraph=(Paragraph) node;
  for(Run run:paragraph.getRuns()){
    System.out.println(run.getText()+" "+layoutCollector.getStartPageIndex());
  }
 }
}

While I ran this code for more than 100 files with 100 pages each, after some time, code struck at getStartPageIndex. I’m testing on my local Windows machine. What might be the reason for this and how can i fix this? No JVM, system configuration, or document formatting issues

@chowdarypradeep.ch If possible, could you please attach a sample document that will allow us to reproduce the problem? We will check the issue and provide you more information.
Also, you should note, that LayoutCollector does not work with nodes in header/footer. You can modify your code like this:

Document doc=new Document(filePath);
LayoutCollector layoutCollector=new LayoutCollector(doc);
       
Iterable<Run> runs = doc.getChildNodes(NodeType.RUN, true);
for(Run run : runs)
{
    // LayoutCollector does not work with nodes in header/footer
    if(run.getAncestor(NodeType.HEADER_FOOTER) == null)
    {
        System.out.println(run.getText()+" "+layoutCollector.getStartPageIndex(run));
    }
}