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: stack size 1039KB #20793

Open
sentry-io bot opened this issue May 10, 2024 · 2 comments
Open

StackOverflowError: stack size 1039KB #20793

sentry-io bot opened this issue May 10, 2024 · 2 comments

Comments

@sentry-io
Copy link

sentry-io bot commented May 10, 2024

Sentry Issue: JETPACK-ANDROID-QXQ

StackOverflowError: stack size 1039KB
    at org.wordpress.android.fluxc.store.PageStore.getPageFromPost(PageStore.kt:168)
    at org.wordpress.android.fluxc.store.PageStore.getPageFromPost$default(PageStore.kt:162)
    at org.wordpress.android.fluxc.store.PageStore.getPageFromPost(PageStore.kt:172)
    at org.wordpress.android.fluxc.store.PageStore.getPageFromPost$default(PageStore.kt:162)
    at org.wordpress.android.fluxc.store.PageStore.getPageFromPost(PageStore.kt:172)
...
(95 additional frame(s) were not displayed)
@sentry-io sentry-io bot added the [Pri] Low label May 10, 2024
@dangermattic
Copy link
Collaborator

Thanks for reporting! 👍

@ravishanker
Copy link
Contributor

The code block below relies on the PageModel class and the getPageFromPost function itself for recursion.

See line val post = posts[postId]!! in PageStore.kt on FluxC, it means that the posts map does not contain a key equal to postId. To fix this, need to handle the case where posts[postId] is null. This code will return null if post is null. Alternatively, replace return null with appropriate error handling for this case:

private fun getPageFromPost(
    postId: Long,
    site: SiteModel,
    posts: Map<Long, PostModel>,
    skipLocalPages: Boolean = true
): PageModel? {
    if (skipLocalPages && (postId <= 0L || !posts.containsKey(postId))) {
        return null
    }
    val post = posts[postId]
    if (post == null) {
        // Handle the case where post is null, for example:
        return null
    }
    return PageModel(post, site, getPageFromPost(post.parentId, site, posts))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants