Uploaded image for project: 'Velocity Tools'
  1. Velocity Tools
  2. VELTOOLS-87

Infinite recursion of the RenderTool.recurse(Context, String) method

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.2, 1.3, 1.x, 1.4, 2.x
    • Fix Version/s: 1.x, 1.4, 2.x
    • Component/s: GenericTools
    • Labels:
      None

      Description

      The recurse method never returns when the vtl template contains a loop (should have been fixed in rev 321227):

      RenderTool tool = new RenderTool();
      VelocityContext ctx = new VelocityContext();
      String vtl = "#set($foo = 'I am [$foo]') $foo";
      System.out.println(tool.recurse(ctx, vtl));

      [StackOverflow]

      the issue is caused by a misplaced '++' operator in the internalRecurse method:

      protected String internalRecurse(Context ctx, String vtl, int count) throws Exception
      {
      String result = eval(ctx, vtl);
      if (result == null || result.equals(vtl))

      { return result; }

      else
      {
      // if we haven't reached our parse depth...
      if (count < parseDepth)

      { // continue recursing return internalRecurse(ctx, result, count++); // <==== BUG: should be '++count' }

      else

      { // abort and return what we have so far //FIXME: notify the developer or user somehow?? return result; }

      }
      }

      The counter is updated after the recursive call returns, which never happens

        Activity

        Hide
        nbubna Nathan Bubna added a comment -

        Thanks! This is now fixed in both the 1.x and 2.x branches.

        Show
        nbubna Nathan Bubna added a comment - Thanks! This is now fixed in both the 1.x and 2.x branches.

          People

          • Assignee:
            Unassigned
            Reporter:
            bcandrea Andrea Bernardo Ciddio
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development