From b92177a2d26f0f96671c848d26c79b08dca13f71 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 23 Jul 2020 17:25:20 +0200 Subject: fix potential nullpointer exception in geoipservice json parsing --- .../se/leap/bitmaskclient/eip/GatewaysManager.java | 33 +++++++++++----------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index e3932cb6..70d757d4 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -174,24 +174,23 @@ public class GatewaysManager { } private void parseGatewaysFromGeoIpServiceJson(Provider provider) { - JSONObject geoIpJson = provider.getGeoIpJson(); - JSONArray gatewaylist = new JSONArray(); - try { - gatewaylist = geoIpJson.getJSONArray(GATEWAYS); - } catch (Exception e) { - e.printStackTrace(); - } + try { + JSONObject geoIpJson = provider.getGeoIpJson(); + JSONArray gatewaylist = geoIpJson.getJSONArray(GATEWAYS); - for (int i = 0; i < gatewaylist.length(); i++) { - try { - String key = gatewaylist.getString(i); - if (gateways.containsKey(key)) { - presortedList.add(gateways.get(key)); - } - } catch (JSONException e) { - e.printStackTrace(); - } - } + for (int i = 0; i < gatewaylist.length(); i++) { + try { + String key = gatewaylist.getString(i); + if (gateways.containsKey(key)) { + presortedList.add(gateways.get(key)); + } + } catch (JSONException e) { + e.printStackTrace(); + } + } + } catch (NullPointerException | JSONException npe) { + npe.printStackTrace(); + } } private JSONObject secretsConfigurationFromCurrentProvider() { -- cgit v1.2.3