Have had HtmlUnit hang up on me executing some web pages. Below is an example url.
After tracing into code the problem occurs when insertBefore is called and (newChild instanceof DomDocumentFragment)==true AND fragment.getChildren is not empty. In my case, the insertBefore is occuring on the same node list that it is iterating against so the iteration goes on forever.
DomNode.java
969: public Node insertBefore(final Node newChild, final Node refChild) { if (newChild instanceof DomDocumentFragment) { final DomDocumentFragment fragment = (DomDocumentFragment) newChild; for (final DomNode child : fragment.getChildren()) { insertBefore(child, refChild); } }
Hi,
Can you post your complete case, as just getting the mentioned page doesn't go into infinite loop.
Also, it seems that the newChild is a child of itself, I wonder how is that possible.
I hope you are using latest version.
Diff:
I was able to step through it in a debugger when it occurred and newChild was certainly a child of itself. I was using 2.15 at the time but it did not appear that the relevant code had been modified since. I have since updated to 2.16.
I supposed it comes down to whether or not newChild==this is a possible situation. If this input is possible then the code fragment above could use protection against this case. If it is not possible, then this is much more of a head scratcher and I will do what I can to replicate the issue in a test program. Regrettably, the code is part of a much larger application that is not possible to post at the moment.
You can put a check in DomNode.basicAppend() and basicInsertBefore(), and throw RuntimeException if the node is 'this' (or parent in basicInsertBefore()), and looking into the stack trace would give an idea.
William, any progress here? We need a way to reproduce this.
Sorry no feedback since years, will close this.