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

null @Parcel @Extra throws exception #208

Closed
justincpollard opened this issue Dec 29, 2016 · 7 comments
Closed

null @Parcel @Extra throws exception #208

justincpollard opened this issue Dec 29, 2016 · 7 comments

Comments

@justincpollard
Copy link

I'm trying to pass an @Parcel annotated @Extra into my activity like so:

@Activity(...)
public class DetailController {

  @Inject
  public DetailController(@Extra(value = "theParcel", optional = true) DetailModel model) {
    ...
  }
}

The DetailModel class is annotated with @Parcel from your Parceler library.

Since this param is optional, sometimes it will be null. Unfortunately, when it is null, the app crashes with this exception:

java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object org.parceler.ParcelWrapper.getParcel()' on a null object reference

It looks like the generated code doesn't take into account that a @Parcel could be null; it calls ParcelWrapper.getParcel() anyway:

((DetailModel)((ParcelWrapper) ExtraUtil.getExtra(this.getIntent().getExtras(), "theParcel", true)).getParcel())

@johncarl81
Copy link
Owner

Hey @justincpollard! I was able to reproduce this and a fix would be pretty straight foward. Are you guys working off of this branch: #196?

@justincpollard
Copy link
Author

Hey John! We're actually using 0.3.0-beta-9. Thanks for the quick response :-)

@johncarl81
Copy link
Owner

^ That should do the trick. Could you try it out?

@justincpollard
Copy link
Author

Hey John, I'll try to take a look next week; off on a brief weekend vacation. Thanks for looking into this :-)

@johncarl81
Copy link
Owner

Cool, thanks for reporting the issue. Let me know when you get back around to it.

@justincpollard
Copy link
Author

Hey John, sorry I never got to this :-( I've been head down for the past 2 months on a feature we're releasing this week.

@johncarl81
Copy link
Owner

Quite alright. I've done quite a bit of testing around this feature and it was about time to clean up the open PRs. Of course, let me know if you have any issues.

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

No branches or pull requests

2 participants