Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-1106

Invoker.format() can cause StackOverflowError

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-JSR-3
    • 1.0
    • None
    • None

    Description

      If in Invoker.format() is called on a map that contains itself e.g.

      def map = [foo: "bar"]
      map.add("map", map)

      It will recurse until StackOverflowError. Probably need a general recursion limiter for format() as this might be an issue for Collections in general and perhaps other objects as well.

      The minimal, non-general fix for this case might be.

      public String toMapString(Map arg) {
      if (arg == null)

      { return "null"; }

      if (arg.isEmpty())

      { return "[:]"; }

      String sbdry = "[";
      String ebdry = "]";
      StringBuffer buffer = new StringBuffer(sbdry);
      boolean first = true;
      for (Iterator iter = arg.entrySet().iterator(); iter.hasNext() {
      if (first)
      first = false;
      else
      buffer.append(", ");
      Map.Entry entry = (Map.Entry) iter.next();
      buffer.append(format(entry.getKey(), true));
      buffer.append(":");
      + if (entry.getValue() == arg)
      + buffer.append("

      {this}

      ");
      + else
      buffer.append(format(entry.getValue(), true));
      }
      buffer.append(ebdry);
      return buffer.toString();
      }

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              matthew.bellew Matthew Bellew
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: