Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XContentBuilder.field : StackOverflowError with Integer[] parameters #1324

Closed
mstein opened this issue Sep 12, 2011 · 0 comments

Comments

Projects
None yet
2 participants
@mstein
Copy link

commented Sep 12, 2011

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.

@kimchy kimchy closed this in 847938a Sep 12, 2011

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.