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

Parse Relation, add/remove object causes ConcurrentModificationException #1070

Open
SkyGanfor opened this issue Oct 28, 2020 · 5 comments
Open
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@SkyGanfor
Copy link

SkyGanfor commented Oct 28, 2020

Hi, I noticed a possible bug in ParseRelations when trying to add or remove an object from a relation. I've found the crash consistently happening when preforming the following:

1: add an object to the relation.
2: add a different object to the same relation.
3: removing the first object from the relation.

Most of the time i get a crash first try, sometimes it doesn't but performing the same list of actions repeatedly will cause it eventually. Here is the full crash:

   java.util.ConcurrentModificationException
        at java.util.HashMap$HashIterator.nextNode(HashMap.java:1441)
        at java.util.HashMap$KeyIterator.next(HashMap.java:1465)
        at com.parse.ParseRelationOperation.removeParseObjectFromSet(ParseRelationOperation.java:124)
        at com.parse.ParseRelationOperation.removeAllParseObjectsFromSet(ParseRelationOperation.java:136)
        at com.parse.ParseRelationOperation.mergeWithPrevious(ParseRelationOperation.java:243)
        at com.parse.ParseObject.performOperation(ParseObject.java:2998)
        at com.parse.ParseRelation.remove(ParseRelation.java:149)

My Android app currently allows an admin user to set permissions for other users, and they do this using a check boxes to allow or deny a user from reading or writing objects. I use a ParseRole and add the users to the "users" ParseRelation.

The admin users are shown a RecyclerView that holds a list of users and a check boxes allowing them to be given permission to read and write. The RecyclerViewAdapter holds a reference to the user ParseRelation for read and write, and the user is added or removed when the checkbox value changes. (Below is the a picture of the UI and my snippet of RecyclerViewAdapter code)

Screenshot_1603895363

            mReadCheckListener = (compoundButton, checked) -> {
            int position = getBindingAdapterPosition();
            if (position != RecyclerView.NO_POSITION) {
                        ParseUser user = getItem(position);
                        if (checked) {
                            mReadRelation.add(user);
                        } else {
                            mReadRelation.remove(user);
                        }
                    }
            };
            mWriteCheckListener = (compoundButton, checked) -> {
             int position = getBindingAdapterPosition();
             if (position != RecyclerView.NO_POSITION) {
                        ParseUser user = getItem(position);
                        if (checked) {
                            mWriteRelation.add(user);
                        } else {
                            mWriteRelation.remove(user);
                        }
                    }
            };

Any help or feedback is appreciated! In the meantime, i've moved over my ParseRelation logic to Cloud Code as a temporary solution to the problem.

@SkyGanfor SkyGanfor changed the title Parse Relation, add/remove object caused ConcurrentModificationException Parse Relation, add/remove object causes ConcurrentModificationException Oct 28, 2020
@mtrezza mtrezza added state:needs-investigation type:bug Impaired feature or lacking behavior that is likely assumed labels Oct 9, 2021
@azlekov
Copy link
Contributor

azlekov commented Nov 30, 2021

@shlusiak do you have idea about this?

@shlusiak
Copy link
Contributor

@L3K0V I haven't had a look yet, but from the stack track I wouldn't be surprised if we are iterating over a HashMap's keys without copying the keys first, before we make any modifications to the Map.

@azlekov
Copy link
Contributor

azlekov commented Nov 30, 2021

@shlusiak can we consider this as closed from your perspective, and if still occurs to open this again?

@shlusiak
Copy link
Contributor

I think the place I fixed this is different though. I'd not be convinced that this is fixed, but I'd be happy to see if the requester can confirm that this is still happening with the latest version that has all my fixes merged in.

@SkyGanfor
Copy link
Author

Sadly I am no longer working on this project, so I'm not able to confirm if this has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

4 participants