Cannot remove because there is no parent.java.lang.IllegalStateException

Hi, i am getting this error when removing/replacing this string, {{Indicative.txt#!IsFinal}} with empty string, “”

{{FullProductName.txt}} resolves to “TestProduct” string value
{{Final.txt#IsFinal}} resolves to “Final” string value
{{Indicative.txt#!IsFinal}} resolves to “” empty string value (correct behaviour) via the removeArgs(ReplacingArgs) method provided by aspose team explicitly

The removeArgs(ReplacingArgs args) method works fine and does not throw any error.

Further investigation found out that this line of code in the zzZm0.class is getting the error

Sample Docx
sample-1.docx (24.5 KB)

ErrorMessage 1 removeArgs(ReplacingArgs args)

ErrorMessage 2

@priyanka9 According to the exception message the node that you are trying to remove is already removed. You can add an additional condition to make sure the node is not already removed:

if(node != null && node.getParentNode() != null)
{
    //....
}

Also, please try specifying FindReplaceDirection.BACKWARD in your FindReplaceOptions :

FindReplaceOptions opt = new FindReplaceOptions(FindReplaceDirection.BACKWARD);

hi @alexey.noskov ,

where do i add the additional check? Below was the change but still getting the same error when replacing the same string, {{Indicative.txt#!IsFinal}}

Additional check change

BACKWARD change

the removeArgs(ReplacingArgs args) method does not throw any error and the control returns back to the caller

@priyanka9 In your code there is one more call of Node.remove() where additional condition is not added. See

// ..........
if (bextPara.getText().trim().equals("")) nextPara.remove();
// ..........

PS: Please do not post code snippets as screenshots. Better post them as text, it will make it much easier to test them.

@alexey.noskov, have added the checks (total 4 places) for the nodes that is calling the .remove() method but still getting the same error.

i cannot copy paste the code snippets as it is in different env with restrictions.

@priyanka9 Could you please create a simple application that will allow us to reproduce the problem on our side? We will check the issue and provide you more information.