-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Closed
Description
After upgrading to 0.17.x from a 0.15.x version in a grails project, I've encountered a StackOverflowError when trying to add a Integer array (Integer[]) using the field() method.
Code sample to reproduce (groovy) :
def json = jsonBuilder().startObject()
Integer[] listofInteger = [1, 2, 3, 4]
json.field("test2", listofInteger)
json.endObject()
Error returned :
Caused by: java.lang.StackOverflowError
at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:568)
at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:601)
at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:601)
at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:601)
(...)
It will also occured when using a Float[] or Double[].
Building the array manually with the array() method will not trigger the error :
def json = jsonBuilder().startObject()
Integer[] listofInteger = [1, 2, 3, 4]
json.startArray("test2")
for (Object o : listofInteger) {
json.value(o);
}
json.endArray()
json.endObject()
The line https://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java#L631 is probably the reason of the issue since an Integer[] will be recognized as a Object[], and will just infinitely call the field(String, Object) method.