Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
richardmorleysmith opened this issue Sep 20, 2023 · 2 comments
Assignees
Labels
bug Confirmed bug that we should fix fixed
Milestone

Comments

@richardmorleysmith
Copy link

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());;
    }
}
@jhy jhy self-assigned this Sep 27, 2023
@jhy jhy added bug Confirmed bug that we should fix fixed labels Sep 27, 2023
@jhy jhy closed this as completed in 9170b1d Sep 28, 2023
@jhy jhy added this to the 1.16.2 milestone Sep 28, 2023
@jhy
Copy link
Owner

jhy commented Sep 28, 2023

Thanks, good find! Fixed. Did you find this in real-world HTML?

@richardmorleysmith
Copy link
Author

Thanks Jonathan! We did yes, but I don't have the site or the original HTML.. would've been interesting to see it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug that we should fix fixed
Projects
None yet
Development

No branches or pull requests

2 participants