mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
FIX: StackOverflowError when using recursive relation within Map
(cherry picked from commit d06bc13b4e1e421546f4997900d5fdc6aa980257)
This commit is contained in:
committed by
Noemi Szemenyei
parent
937b15c07a
commit
4d7a3d135c
@@ -1,7 +1,10 @@
|
||||
package io.ebean.bean;
|
||||
|
||||
import io.ebean.common.BeanMap;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Helps build toString content taking into account recursion.
|
||||
@@ -104,6 +107,8 @@ public final class ToStringBuilder {
|
||||
}
|
||||
} else if (value instanceof Collection) {
|
||||
addCollection((Collection<?>) value);
|
||||
} else if (value instanceof Map) {
|
||||
addMap(((Map<?, ?>) value));
|
||||
} else {
|
||||
String content = String.valueOf(value);
|
||||
if (content.length() > TRIM_LENGTH) {
|
||||
@@ -117,6 +122,28 @@ public final class ToStringBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
public void addMap(Map<?,?> map) {
|
||||
if (map == null || map.isEmpty()) {
|
||||
sb.append("{}");
|
||||
} else {
|
||||
boolean firstElement = true;
|
||||
sb.append("{");
|
||||
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||
if (firstElement) {
|
||||
firstElement = false;
|
||||
} else {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append(entry.getKey()).append(":");
|
||||
value(entry.getValue());
|
||||
if (counter > MAX) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
sb.append("}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a collection of values.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user