Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-5578

Json rendering is using recursion for processing flat trees and causes stack overflows

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • Commons JSON 2.0.16
    • Commons JSON 2.0.18
    • Commons
    • None

    Description

      ResourceTraversor.collectChildren is unnecessarily using recursion and causes stack overflows for flat trees.

      Example: for a node with 10k direct children it adds 10k calls on the stack. This should be implemented in an iterative way or at most it should do recursion only for the tree depth.

      [1] https://github.com/apache/sling/blob/7c4a53755aed1211c9af313a3973cd2543a7bbe0/bundles/commons/json/src/main/java/org/apache/sling/commons/json/sling/ResourceTraversor.java#L84

      Attachments

        1. SLING-5578.diff
          0.8 kB
          Marius Petria
        2. SLING-5578.test.diff
          41 kB
          Marius Petria

        Activity

          People

            bdelacretaz Bertrand Delacretaz
            mpetria Marius Petria
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: