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 marshal function with nullable fragments #2404

Merged

Conversation

vkondrav
Copy link
Contributor

@vkondrav vkondrav commented Jun 27, 2020

While upgrading to release 2.1.0 I came across a strange problem where the generated marshal function was no longer checking nullability of fragment before executing writer.writeFragment. This resulted in a null pointer exception when calling marshaller(). Although this did not cause any problem during normal execution we do have a point in the app where we write a fragment back to apolloStore. This is where the NullPointer Exception would occur.

Before

    public ResponseFieldMarshaller marshaller() {
      return new ResponseFieldMarshaller() {
        @Override
        public void marshal(ResponseWriter writer) {
          writer.writeFragment(downloadAppDeepLinkFragment.marshaller());
        }
      };
    }

After

    public ResponseFieldMarshaller marshaller() {
      return new ResponseFieldMarshaller() {
        @Override
        public void marshal(ResponseWriter writer) {
          final DownloadAppDeepLinkFragment $downloadAppDeepLinkFragment = downloadAppDeepLinkFragment;
          if ($downloadAppDeepLinkFragment != null) {
            $downloadAppDeepLinkFragment.marshaller().marshal(writer);
          }
        }
      };
    }

@apollo-cla
Copy link

@vkondrav: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

Copy link
Contributor

@sav007 sav007 left a comment

Choose a reason for hiding this comment

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

Thx !!!

@martinbonnin martinbonnin merged commit e87d9df into apollographql:master Jun 29, 2020
@vkondrav vkondrav deleted the vkondrav/nullable-fragment-marshal branch June 29, 2020 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants