brarcher / loyalty-card-locker

Stores your barcode-based store/loyalty cards on your phone
GNU General Public License v3.0
171 stars 29 forks source link

NPE when sharing a card #342

Closed brarcher closed 4 years ago

brarcher commented 4 years ago

The following exception is reported multiple times from Beta users from Play on release v0.26:

java.lang.NullPointerException: 
  at protect.card_locker.ImportURIHelper.toUri (ImportURIHelper.java:60)
  at protect.card_locker.ImportURIHelper.startShareIntent (ImportURIHelper.java:77)
  at protect.card_locker.MainActivity.onContextItemSelected (MainActivity.java:210)

This is the following line:

uriBuilder.appendQueryParameter(HEADER_COLOR, loyaltyCard.headerColor.toString());

Android Studio does surface a warning that headerColor may be null, but that may be a general warning, as nothing in the contract to toUri prevents a card field from being null. The question is, under what conditions is the header color null?

brarcher commented 4 years ago

@TheLastProject, are you interested in taking a look at this issue with sharing loyalty cards? If not, I can take a look when I have time.

Right now v0.26 is in Beta. I'd like to address this issue before taking the new features out of Beta.

TheLastProject commented 4 years ago

It is allowed to be null in the database so my guess would be that these are old loyalty cards saved before the header and title colour fields were introduced. The rest of the code has null checks for the header fields to deal with this.

I will soon (probably this evening) patch this as follows: