Skip to content

StackOverflowError when calling Element.cssSelector() on deeply nested element #2001

@richardmorleysmith

Description

@richardmorleysmith

As per title!

Here is a program which reproduces the issue:

import org.jsoup.nodes.Element;

public class Test {
    public static void main(String[] args) {
        Element element = new Element("element");

        // Create a long chain of elements
        for (int i = 0; i < 5000; i++) {
            Element elem2 = new Element("element" + i);
            element.appendChild(elem2);
            element = elem2;
        }
        
        // Crashes with StackOverflowError
        System.out.println(element.cssSelector());;
    }
}

Metadata

Metadata

Assignees

Labels

bugA confirmed bug, that we should fixfixedAn {bug|improvement} that has been {fixed|implemented}

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions