Skip to content

Fix StackOverflowError when merging ParseObject from JSON #925

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jdk:
before_install:
- pip install --user codecov
- mkdir "$ANDROID_HOME/licenses" || true
- echo "d56f5187479451eabf01fb78af6dfcb131a6481e" > "$ANDROID_HOME/licenses/android-sdk-license"
- echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" >> "$ANDROID_HOME/licenses/android-sdk-license"

script:
- ./gradlew clean testDebugUnitTest jacocoTestReport
Expand Down
2 changes: 1 addition & 1 deletion parse/src/main/java/com/parse/ParseObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -4076,7 +4076,7 @@ public Init(String className) {
objectId = state.objectId();
createdAt = state.createdAt();
updatedAt = state.updatedAt();
availableKeys = Collections.synchronizedSet(state.availableKeys());
availableKeys = Collections.synchronizedSet(new HashSet<>(state.availableKeys()));
for (String key : state.keySet()) {
serverData.put(key, state.get(key));
availableKeys.add(key);
Expand Down
27 changes: 26 additions & 1 deletion parse/src/test/java/com/parse/ParseObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -128,7 +129,7 @@ public void testFromJSONPayload() throws JSONException {

//endregion

//region testGetter
//region testFromJson

@Test
public void testFromJSONPayloadWithoutClassname() throws JSONException {
Expand All @@ -137,6 +138,30 @@ public void testFromJSONPayloadWithoutClassname() throws JSONException {
assertNull(parseObject);
}

@Test
public void testFromJsonWithLdsStackOverflow() throws JSONException {
ParseObject localObj = ParseObject.createWithoutData("GameScore", "TT1ZskATqS");
OfflineStore lds = mock(OfflineStore.class);
Parse.setLocalDatastore(lds);

when(lds.getObject(eq("GameScore"), eq("TT1ZskATqS"))).thenReturn(localObj);

JSONObject json = new JSONObject("{" +
"\"className\":\"GameScore\"," +
"\"createdAt\":\"2015-06-22T21:23:41.733Z\"," +
"\"objectId\":\"TT1ZskATqS\"," +
"\"updatedAt\":\"2015-06-22T22:06:18.104Z\"" +
"}");
ParseObject obj;
for (int i = 0; i < 50000; i++) {
obj = ParseObject.fromJSON(json, "GameScore", ParseDecoder.get(), Collections.<String>emptySet());
}
}

//endregion

//region testGetter

@Test
public void testRevert() throws ParseException {
List<Task<Void>> tasks = new ArrayList<>();
Expand Down