-
Notifications
You must be signed in to change notification settings - Fork 586
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
Fix segmentation fault when pushing a class object based on Realm.Object to a list #3610
Conversation
d589ba7
to
f27e77c
Compare
Let's have a face 2 face conversation around this, as I don't think this is the right approach. In my understanding of the current implementation (and limitations) of our "class-based schema" support, we do not support users to explicitly call the schema class's constructor, hence it's undefined behaviour and not something we should be providing work arounds for. I also agree that we should continue improving the class based support, ideally to the point where explicitly calling the class constructor is supported, but this requires more work than this PR suggests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
e9c0533
to
1853669
Compare
@kraenhansen and I decided it would make more sense to throw an exception instead of implicitly creating the object on push. We also added an exception when someone tries to use the class constructor to create an object, as this breaks the second time. In the future we will rethink class support. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's definitely better to have consistent behaviour & exceptions instead of crashes, but should we word this as temporary fixes?
5fbdf42
to
0493f50
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few nitpicks and a general question.
Other than that, LGTM
} | ||
} | ||
|
||
TodoItem.schema = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Question] The tests usually put their schemas in schemas.js
.. Is there any specific reason why these don't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I would perhaps like to have a conversation about this. I find in tests it is best to not put such things in separate files, as they rarely are reused and it makes the reader of the test have a nicer time following what is happening. So I guess that's more my personal style and opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion on the subject myself..
@kneth ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using the same schemas across tests, so we avoid code duplication with schemas.js
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are going to create a new issue for this where we will address refactor the tests and write a style guide.
When creating a class that extends Realm.Object and pushing the instantiated object to a list, a segmentation fault would occur. The problem is that realm was assuming that if the object is of type Realm.Object that it has already been created. This assumption was causing a null pointer to be dereferenced which had caused the segmentation fault. The logic now checks for null and throws an exception. Also attempting to create an object with an unmanged instance of Realm.Object will throw an exception. This is to avoid future attempts to create which fail, as the prototype has been changed.
0493f50
to
096d7e1
Compare
What, How & Why?
When creating a class that extends Realm.Object and pushing the instantiated object to a list, a segmentation fault would occur.
The problem is that realm was assuming that if the object is of type Realm.Object that it has already been created. This assumption was causing a null pointer to be dereferenced which had caused the segmentation fault. The logic now checks for null and throws an exception.
Also attempting to create an object with an unmanged instance of Realm.Object will throw an exception. This is to avoid future attempts to create which fail, as the prototype has been changed.
☑️ ToDos
📝Compatibility
label is updated or copied from previous entry📝 Public documentation PR created or is not necessary💥Breaking
label has been applied or is not necessaryIf this PR adds or changes public API's:
typescript definitions file is updatedjsdoc files updatedChrome debug API is updated if API is available on React Native