Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0-JSR-3
-
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)
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("
");
+ else
buffer.append(format(entry.getValue(), true));
}
buffer.append(ebdry);
return buffer.toString();
}
Attachments
Issue Links
- relates to
-
GROOVY-3250 StackOverflowError in List and Map formatting
- Open