scala-maxmind-iplookups icon indicating copy to clipboard operation
scala-maxmind-iplookups copied to clipboard

`null` fields in `IpLocation`

Open ncreep opened this issue 3 years ago • 0 comments

Hi,

Library version: 0.7.1

Expected behavior: Fields in the IpLocation class should never be null.

Actual behavior: (At least) the IpLocation.countryCode field can sometimes be null.

Steps to reproduce:

The IpLocation.apply function that takes a CityResponse value does not check for null values. So this code:

val cityResponse = new com.maxmind.geoip2.model.CityResponse(null, null, null, null, null, null, null, null, null, null)

com.snowplowanalytics.maxmind.iplookups.model.IpLocation(cityResponse) 
// IpLocation(null,null,None,None,Some(0),0.0,0.0,None,None,None,None,false,null,0)

Produces null in all 3 String fields in IpLocation.

Note, we've hit a null in countryCode in a real production scenario, when looking-up an actual IP, rather than the artificial code above.

Ideally, it would be convenient to reflect the possibility of missing fields by wrapping the relevant fields in Option. If that's not possible, maybe it's possible to have some non-null fallback? (Although using an empty string seems bad as well.)

If you point me in the right direction, I can open a pull-request with a fix.

Thanks.

ncreep avatar Sep 29 '20 18:09 ncreep