johncarl81 / transfuse

:syringe: Transfuse - A Dependency Injection and Integration framework for Google Android
http://androidtransfuse.org/
Apache License 2.0
220 stars 28 forks source link

null @Parcel @Extra throws exception #208

Closed justincpollard closed 7 years ago

justincpollard commented 7 years ago

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 commented 7 years ago

Hey @justincpollard! I was able to reproduce this and a fix would be pretty straight foward. Are you guys working off of this branch: https://github.com/johncarl81/transfuse/pull/196?

justincpollard commented 7 years ago

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

johncarl81 commented 7 years ago

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

justincpollard commented 7 years ago

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

johncarl81 commented 7 years ago

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

justincpollard commented 7 years ago

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 commented 7 years ago

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.