Parse-SDK-Android icon indicating copy to clipboard operation
Parse-SDK-Android copied to clipboard

Enabling Local Datastore causes ParseParcelEncoder Stack OverFlow

Open SkyGanfor opened this issue 5 years ago • 3 comments

Hi, I recently came across what I suppose to be a bug in the ParseParcelEncoder for android, specifically when parceling ParseObject subclasses of mine with local datastore enabled (LDS). This bug seems to occur in the onSaveInstanceState method of a subclassed ParseObject, specifically when trying to store a populated ArrayList of Parcelable Objects in the bundle. This causes the onSaveInstanceState method to continually loop until a Stack Overflow occurs. Commenting out the line of code storing the ArrayList fixes the problem (storing Ints, Strings, singular Parcelable objects, etc are unaffected). The other fix is disabling LDS, which causes ArrayLists to be parceled just fine.

I've included some screenshots of parts of my code for reference, and the full error is viewable in the attached PDF file. (Error starts on line 250):

Stack Overflow Error: Screen Shot 2020-02-11 at 11 06 40 AM

Subclassed Object (SubJob Object Arraylist is what is causing the issue) Screen Shot 2020-02-11 at 10 46 37 AM

PDF containing the full error log (the error continues for almost 300 pages, but since its the same error looping i've shortened it so it can be uploaded here): AndroidSimParseLDSOverflow.pdf

You can recreate this bug by creating a subclassed parse object, implementing the onSaveInstanceState method, and putting an array-list of Parcelable Objects in the bundle. Also make sure to enable LDS. Trigger the onSaveInstanceState method by navigating from one activity to another using the code below :

   Bundle data = new Bundle();
   data.putParcelable("YOUR_PARCELABLE_ID", YOUR-SUBCLASSED-PARSE-OBJECT);
   Intent intent = new Intent(YOUR_CONTEXT, YOUR-SECOND-ACTIVITY.class);
   intent.putExtras(data);
   mContext.startActivity(intent);

If you have any questions or need more info please let me know and I'll do my best to provide it.

-Adam

SkyGanfor avatar Feb 11 '20 17:02 SkyGanfor

Upon further investigation into this issue, I discovered that ParseParcelEncoder.java actually mentions this StackOverflow issue in a comment.

* This is capable of parceling {@link ParseObject}s, but the result can likely be a * {@link StackOverflowError} due to circular references in the objects tree. * When needing to parcel {@link ParseObject}, use the stateful {@link ParseObjectParcelEncoder}.

@Jawnnypoo, you seem to have written ParseParcelEncoder and ParseObjectParcelEncoder. Would you know of a work around or possible bug fix when trying to parcel a list of Parse Objects?

SkyGanfor avatar Mar 21 '20 17:03 SkyGanfor

Hey there, I did not write those classes, but rather refactored them and made them fit the rules of our formatter. I do not currently know of a workaround or fix, sorry.

Jawnnypoo avatar Mar 21 '20 23:03 Jawnnypoo

That's alright, thanks for the response!

SkyGanfor avatar Mar 22 '20 00:03 SkyGanfor