Error while extracting content between noes

Hi,
I am tried to extracting content between hidden special words. But while extracting some content I am facing below error,

java.lang.ClassCastException: com.aspose.words.BookmarkEnd cannot be cast to com.aspose.words.CompositeNode
	at Main.extractContent(Main.java:162)
	at Main.getHtmlContentFromBookMark(Main.java:97)
	at Main.SaveInItem(Main.java:64)
	at Main.main(Main.java:50)

and extracting half of the content. I am attaching the sample code sample.zip (5.9 KB)
and input file input.docx (20.5 KB)

Please help me to fix the issue.

Thank you

@Gptrnt You consider that every direct child of a body is a CompositeNode but in your document there is also a BookmarkEnd node on the same level. You should update your code to handle this case. For example you could cast to CompositeNode only when calling processMarker() and add an extra check:

Node cloneNode = currNode.deepClone(true);
...
if (isStartingNode && cloneNode instanceof CompositeNode) {
    processMarker((CompositeNode)cloneNode, nodes, originalStartNode, isInclusive, isStartingNode, isEndingNode);
...
if (isEndingNode && cloneNode instanceof CompositeNode) {
    processMarker((CompositeNode)cloneNode, nodes, originalEndNode, isInclusive, isStartingNode, isEndingNode);