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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.2, 1.3, 1.x, 1.4, 2.x
    • 1.x, 1.4, 2.x, 3.0
    • GenericTools
    • 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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: