Avoid modifying managed RealmList when user executes a query.#3812
Avoid modifying managed RealmList when user executes a query.#3812
Conversation
|
Remind me why do we need to transform all the getter/setters in the constructor? Can we just skip the transforming for the constructor (at least the default one)? Ask user to have check of |
|
@beeender mainly for |
|
You have provided a workaround to #3809, but I believe that Realm Java should be as easy to use as possible. From that point of view, I think this proposal makes sense. |
|
I would really like to avoid anything like the above. It doesn't really solve the problem of being intuitive to use since you would need to read the documentation for both this and doing the work-around in #3809. If given a choice between the two I would probably prefer to just document the current bug and how to work around it instead of introducing new methods of questionable value? However, could it be possible to inject that code using our transformer? That way people wouldn't need to do anything? |
|
@cmelchior That's a great idea. |
This reverts commit 2e1b9da.
|
Adding
My current conclusion is that we should not inject |
WIP
In model's constructor, calling mutator methods of managed
RealmListmust be ignored ifgetAcceptDefaultValue$realm()isfalseor the name of the field is in the ignore list.However,
RealmListhas many methods which is meant to modify itself and that is very hard to provide a natural non-op behavior. Of course it breaks expectedListbehavior, too.For example:
For that reason, I'm leaning toward adding a method
public static boolean RealmObject#acceptsDefaultValue(RealmModel)which returnsfalsewhen the assigned values are ignored in the constructor.And when that method returns
false, all mutator methods inRealmListthrows an exception (this is not an breaking chance since we are already throwingIllegalStateExceptionnow).After introducing
acceptsDefaultValue(RealmModel), users can skip any assignment of default values like:As Christian commented on #3812 (comment), I think we can automatically add the check by our transformer in most cases. We need to check that adding the code to the following constructor is valid.
fixes #3809