From 6425d6ab1a847e3164194e612f4a9eca6b8414eb Mon Sep 17 00:00:00 2001 From: Ace Date: Fri, 3 Jun 2016 19:27:20 +0530 Subject: [PATCH] Adding null check for operations response --- .../android/util/AndroidAPIUtils.java | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java index 99063feb4..3635bae73 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java @@ -312,26 +312,31 @@ public class AndroidAPIUtils { private static void updateApplicationList(Operation operation, DeviceIdentifier deviceIdentifier) throws ApplicationManagementException { // Parsing json string to get applications list. - JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse()); - JsonArray jsonArray = jsonElement.getAsJsonArray(); - Application app; - List applications = new ArrayList(jsonArray.size()); - for (JsonElement element : jsonArray) { - app = new Application(); - app.setName(element.getAsJsonObject(). - get(AndroidConstants.ApplicationProperties.NAME).getAsString()); - app.setApplicationIdentifier(element.getAsJsonObject(). - get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString()); - app.setPlatform(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS) != null) { - app.setMemoryUsage(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS).getAsInt()); - } - if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION) != null) { - app.setVersion(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION).getAsString()); + if (operation.getOperationResponse() != null) { + JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse()); + JsonArray jsonArray = jsonElement.getAsJsonArray(); + Application app; + List applications = new ArrayList(jsonArray.size()); + for (JsonElement element : jsonArray) { + app = new Application(); + app.setName(element.getAsJsonObject(). + get(AndroidConstants.ApplicationProperties.NAME).getAsString()); + app.setApplicationIdentifier(element.getAsJsonObject(). + get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString()); + app.setPlatform(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS) != null) { + app.setMemoryUsage(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS).getAsInt()); + } + if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION) != null) { + app.setVersion(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION).getAsString()); + } + applications.add(app); } - applications.add(app); + getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications); + } else { + log.error("Operation Response is null."); } - getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications); + }