From f68939b5b2e2bd0d90d0f2a35e435168b75ebd47 Mon Sep 17 00:00:00 2001 From: Larry Sachs Date: Fri, 16 Sep 2016 10:22:28 -0700 Subject: [PATCH] Throw OcException for invalid (null) parameters in Java Layer of android_api. [IOT-1254] -- OcPlatform.notifyListOfObservers() ocObservationIdList is null. [IOT-1255] -- OcResource.observe() observeType is null. [IOT-1256] -- OcPlatform.bindResources() ocResourceHandleList is null. [IOT-1257] -- OcPlatform.unbindResources() ocResourceHandleList is null. Change-Id: Ib1c20dba6d0e85a05e8099ba1276d65334560c9d Signed-off-by: Larry Sachs Reviewed-on: https://gerrit.iotivity.org/gerrit/11877 Tested-by: jenkins-iotivity Reviewed-by: jihwan seo Reviewed-by: Rick Bell --- .../src/main/java/org/iotivity/base/OcPlatform.java | 18 ++++++++++++++++++ .../src/main/java/org/iotivity/base/OcResource.java | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java index f699e16..589bdf1 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java @@ -172,6 +172,10 @@ public final class OcPlatform { OcResourceResponse ocResourceResponse) throws OcException { OcPlatform.initCheck(); + if (ocObservationIdList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "ocObservationIdList cannot be null"); + } + byte[] idArr = new byte[ocObservationIdList.size()]; Iterator it = ocObservationIdList.iterator(); int i = 0; @@ -211,6 +215,10 @@ public final class OcPlatform { QualityOfService qualityOfService) throws OcException { OcPlatform.initCheck(); + if (ocObservationIdList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "ocObservationIdList cannot be null"); + } + byte[] idArr = new byte[ocObservationIdList.size()]; Iterator it = ocObservationIdList.iterator(); int i = 0; @@ -631,6 +639,11 @@ public final class OcPlatform { OcResourceHandle ocResourceCollectionHandle, List ocResourceHandleList) throws OcException { OcPlatform.initCheck(); + + if (ocResourceHandleList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "ocResourceHandleList cannot be null"); + } + OcPlatform.bindResources0( ocResourceCollectionHandle, ocResourceHandleList.toArray( @@ -672,6 +685,11 @@ public final class OcPlatform { OcResourceHandle ocResourceCollectionHandle, List ocResourceHandleList) throws OcException { OcPlatform.initCheck(); + + if (ocResourceHandleList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "ocResourceHandleList cannot be null"); + } + OcPlatform.unbindResources0( ocResourceCollectionHandle, ocResourceHandleList.toArray( diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java b/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java index 34d7c41..c0fd090 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java @@ -370,6 +370,11 @@ public class OcResource { public void observe(ObserveType observeType, Map queryParamsMap, OnObserveListener onObserveListener) throws OcException { + + if (observeType == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "observeType cannot be null"); + } + this.observe( observeType.getValue(), queryParamsMap, -- 2.7.4