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

Fix possible NRE in expandable field accessors #1660

Merged
merged 1 commit into from
Jun 12, 2019
Merged

Conversation

ob-stripe
Copy link
Contributor

r? @remi-stripe
cc @stripe/api-libraries

A few changes to avoid possible NullReferenceExceptions when using accessors for expandable fields:

  • add safe navigation operator to all getters
  • use new helper methods for all setters:
    • when setting the ID, SetExpandableFieldId will create the ExpandableField<T> instance if it doesn't exist already, and resets the expanded object if the IDs don't match
    • when setting the expanded object, SetExpandableFieldObject will create the ExpandableField<T> instance if it doesn't exist already.

I've written some generic tests for StripeEntity to test the helper methods, and also a few tests for Customer.DefaultSource so that we test at least one "real" expandable field. It doesn't seem realistic to write tests for every single expandable field accessor, so I guess we'll just have to be careful with copy/paste when adding new expandable fields.

(I have a vague idea for simplifying the expandable field accessor mess, but I'll keep that for a future major version.)

(Also, I think the entity classes should not have public setters at all and should be implemented as immutable value objects, but that would require writing very long constructor methods, so not going to do that until we can codegen .NET.)

Fixes #1659.

Copy link
Contributor

@remi-stripe remi-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me and thanks for adding the detailed tests.

OOC is it possible to ask one of the affected developers to test your fix before we release to make sure it covers their use-case?

@stripe-ci stripe-ci assigned ob-stripe and unassigned remi-stripe Jun 11, 2019
@ob-stripe ob-stripe merged commit 93bc5ad into master Jun 12, 2019
@ob-stripe ob-stripe deleted the ob-fix-exp-setters branch June 12, 2019 23:38
@ob-stripe
Copy link
Contributor Author

Released as 27.1.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

27.1 setters are back, but throw NullReferenceException
3 participants