IOT-3045 Fix return type of getResourceHandleAtUri 75/24575/3
authorGeorge Nash <george.nash@intel.com>
Wed, 4 Apr 2018 19:27:47 +0000 (12:27 -0700)
committerRick Bell <richard.s.bell@intel.com>
Thu, 5 Apr 2018 06:09:26 +0000 (06:09 +0000)
OcPlatfrom.getResourceAtUri should return null
when a resource is not found at the specified
URI. The class JniOcResourceHandle returned
a non-null value even when a null resourceHandle
was passed into the function. The assumption
when the code was originally created was that
it would return null. This assumption was incorrect.

This was tested by modifying simpleserver sample
Modifications not included as part of this commit.

Bug: https://jira.iotivity.org/browse/IOT-3045
Change-Id: I3e923dca3415e9e0ec473b1dd4ff4619538f325b
Signed-off-by: George Nash <george.nash@intel.com>
java/jni/JniOcPlatform.cpp

index 9ea86ba..41366ca 100644 (file)
@@ -1500,7 +1500,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_getResourceHandleAtU
     OCResourceHandle resourceHandle;
 
     resourceHandle = OCGetResourceHandleAtUri(resourceUri.c_str());
-
+    if (nullptr == resourceHandle)
+    {
+        return nullptr;
+    }
     JniOcResourceHandle* jniHandle = new JniOcResourceHandle(resourceHandle);
     jlong handle = reinterpret_cast<jlong>(jniHandle);
     jobject jResourceHandle;