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

StackOverflowError for large maps #197

Closed
GoogleCodeExporter opened this issue Apr 19, 2015 · 2 comments
Closed

StackOverflowError for large maps #197

GoogleCodeExporter opened this issue Apr 19, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?

  public void testLargeGsonMapRoundTrip() throws Exception {
    Map<Long, Long> original = Maps.newHashMap();
    for (long i = 0; i < 50000; i++) {
      original.put(i, i + 1);
    }

    Gson gson = new Gson();
    String json = gson.toJson(original);

    Type longToLong = new TypeToken<Map<Long, Long>>(){}.getType();
    gson.fromJson(json, longToLong);
  }

What is the expected output? 

Gson should not recurse when parsing map entries. Parsing JSON is not that 
hard, so I suggest not using Javacc. 

What do you see instead?

com.google.gson.JsonParseException: Failed parsing JSON source: 
java.io.StringReader@186d484 to Json
    at com.google.gson.JsonParser.parse(JsonParser.java:61)
    at com.google.gson.Gson.fromJson(Gson.java:443)
    at com.google.gson.Gson.fromJson(Gson.java:396)
...

Caused by: java.lang.StackOverflowError
    at 
com.google.gson.JsonParserJavacc.jj_3R_5(JsonParserJavacc.java:449)
    at 
com.google.gson.JsonParserJavacc.jj_3R_4(JsonParserJavacc.java:456)
    at 
com.google.gson.JsonParserJavacc.jj_3R_2(JsonParserJavacc.java:443)
    at 
com.google.gson.JsonParserJavacc.jj_3_1(JsonParserJavacc.java:462)
    at 
com.google.gson.JsonParserJavacc.jj_2_1(JsonParserJavacc.java:428)
    at 
com.google.gson.JsonParserJavacc.JsonNumber(JsonParserJavacc.java:276)
    at 
com.google.gson.JsonParserJavacc.JsonValue(JsonParserJavacc.java:213)
    at com.google.gson.JsonParserJavacc.Pair(JsonParserJavacc.java:112)
    at 
com.google.gson.JsonParserJavacc.Members(JsonParserJavacc.java:95)
    at 
com.google.gson.JsonParserJavacc.Members(JsonParserJavacc.java:99)
...


What version of the product are you using? On what operating system?

1.4 (in google3)

Original issue reported on code.google.com by skybr...@google.com on 9 Mar 2010 at 7:44

@GoogleCodeExporter
Copy link
Author

I have the same problem. My Input is a 18MB json file, which has basically the
structure of Map<String, <Map, <String, Map<String, String>>>>

(I 'm not at liberty to provide the file)

There are only few keys on first level, so each "value" is quite large

Original comment by CptMa...@googlemail.com on 4 May 2010 at 9:26

@GoogleCodeExporter
Copy link
Author

r543 fixes this issue. Thanks for the bug report. The fix also improved Gson
performance by 20-30%.

Original comment by inder123 on 19 May 2010 at 9:25

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant