Hello Ottomata, I'd like you to do a code review. Please visit
https://gerrit.wikimedia.org/r/188013 to review the following change. Change subject: Fix NPE when Country Geocoding fails to detect country ...................................................................... Fix NPE when Country Geocoding fails to detect country Change-Id: I36c279ac67dfd20d4024b6bfd0c441302304accc --- M refinery-core/src/main/java/org/wikimedia/analytics/refinery/core/Geocode.java M refinery-hive/src/test/java/org/wikimedia/analytics/refinery/hive/TestGeocodedCountryUDF.java 2 files changed, 23 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/analytics/refinery/source refs/changes/13/188013/1 diff --git a/refinery-core/src/main/java/org/wikimedia/analytics/refinery/core/Geocode.java b/refinery-core/src/main/java/org/wikimedia/analytics/refinery/core/Geocode.java index 6f7eb26..aefa3ba 100644 --- a/refinery-core/src/main/java/org/wikimedia/analytics/refinery/core/Geocode.java +++ b/refinery-core/src/main/java/org/wikimedia/analytics/refinery/core/Geocode.java @@ -96,7 +96,11 @@ InetAddress ipAddress = InetAddress.getByName(ip); CountryResponse response = countryDatabaseReader.country(ipAddress); Country country = response.getCountry(); - return country.getIsoCode(); + String ret = country.getIsoCode(); + if (ret == null) { + ret = UNKNOWN_COUNTRY_CODE; + } + return ret; } catch (UnknownHostException hEx) { LOG.warn(hEx); return UNKNOWN_COUNTRY_CODE; diff --git a/refinery-hive/src/test/java/org/wikimedia/analytics/refinery/hive/TestGeocodedCountryUDF.java b/refinery-hive/src/test/java/org/wikimedia/analytics/refinery/hive/TestGeocodedCountryUDF.java index 1c39d4b..fe23632 100644 --- a/refinery-hive/src/test/java/org/wikimedia/analytics/refinery/hive/TestGeocodedCountryUDF.java +++ b/refinery-hive/src/test/java/org/wikimedia/analytics/refinery/hive/TestGeocodedCountryUDF.java @@ -101,4 +101,22 @@ result = (Text)geocodedCountryUDF.evaluate(args); assertEquals("ISO country code check", "--", result.toString()); } + + @Test + public void testIPWithoutIsoCode() throws HiveException { + ObjectInspector value1 = PrimitiveObjectInspectorFactory.javaStringObjectInspector; + ObjectInspector[] initArguments = new ObjectInspector[]{value1}; + GeocodedCountryUDF geocodedCountryUDF = new GeocodedCountryUDF(); + + geocodedCountryUDF.initialize(initArguments); + geocodedCountryUDF.configure(MapredContext.init(false, new JobConf())); + + String ip = "2a02:d500::"; // IP for EU + DeferredObject[] args = new DeferredObject[] { new DeferredJavaObject(ip) }; + Text result = (Text)geocodedCountryUDF.evaluate(args); + assertEquals("ISO country code check", "--", result.toString()); + + // Consistency trumps good style. Hence not closing the UDF, as other + // UDFs in this test case aren't closed either :-( + } } -- To view, visit https://gerrit.wikimedia.org/r/188013 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I36c279ac67dfd20d4024b6bfd0c441302304accc Gerrit-PatchSet: 1 Gerrit-Project: analytics/refinery/source Gerrit-Branch: master Gerrit-Owner: QChris <christ...@quelltextlich.at> Gerrit-Reviewer: Ottomata <o...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits