google / libaddressinput

Google’s postal address library, powering Android and Chromium
Apache License 2.0
580 stars 104 forks source link

Fix crash from constant data missing ID data #196

Open jeffdgr8 opened 4 years ago

jeffdgr8 commented 4 years ago

It's possible for StandardAddressVerifier.verifyFields() to crash with:

Fatal Exception: java.lang.NullPointerException: Cannot use null as key
       at com.google.i18n.addressinput.common.Util.checkNotNull(Util.java:123)
       at com.google.i18n.addressinput.common.FieldVerifier.isCountryKey(FieldVerifier.java:439)
       at com.google.i18n.addressinput.common.FieldVerifier.populate(FieldVerifier.java:171)
       at com.google.i18n.addressinput.common.FieldVerifier.<init>(FieldVerifier.java:105)
       at com.google.i18n.addressinput.common.FieldVerifier.refineVerifier(FieldVerifier.java:283)
       at com.google.i18n.addressinput.common.StandardAddressVerifier$Verifier.run(StandardAddressVerifier.java:132)
       at com.google.i18n.addressinput.common.StandardAddressVerifier.verifyFields(StandardAddressVerifier.java:86)

This happens if ClientData.fetchDataIfNotAvailable() fails to fetch data from the server in CacheData.fetchDynamicData(), resulting in getting the data from the RegionDataConstants with CacheData.getFromRegionDataConstants(). The constants data lacks the id key values that are returned from the server, which are required by FieldVerifier.isCountryKey().

This change fixes this by adding the id value for region constant data from its LookupKey.