[IOT-1676]Removing Unreachable code from Notification Service JNI 67/15567/6
authorabitha.s <abitha.s@samsung.com>
Tue, 13 Dec 2016 13:43:14 +0000 (19:13 +0530)
committerUze Choi <uzchoi@samsung.com>
Mon, 19 Dec 2016 10:16:02 +0000 (10:16 +0000)
Change-Id: If28fb835a94f67f2d37f50ab721ae68ed9234559
Signed-off-by: abitha.s <abitha.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/15567
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Chihyun Cho <ch79.cho@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/android/notification-service/src/main/jni/consumer/JniNotificationConsumer.cpp
service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.cpp
service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp

index 1eb4ef0..2eb79b3 100755 (executable)
@@ -73,37 +73,45 @@ static JNIEnv *GetJNIEnv(jint *ret)
 jobject getJavaProviderState(JNIEnv *env, OIC::Service::NSProviderState state)\r
 {\r
     LOGD ("ConsumerService_getJavaProviderState - IN");\r
+    jobject providerState = NULL;\r
     switch (state)\r
     {\r
         case OIC::Service::NSProviderState::ALLOW:\r
             {\r
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_ProviderState,\r
                                           "ALLOW", "Lorg/iotivity/service/ns/consumer/Provider$ProviderState;");\r
-                return env->GetStaticObjectField(g_cls_ProviderState, fieldID);\r
+                providerState = env->GetStaticObjectField(g_cls_ProviderState, fieldID);\r
+                break;\r
             }\r
         case OIC::Service::NSProviderState::DENY:\r
             {\r
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_ProviderState,\r
                                           "DENY", "Lorg/iotivity/service/ns/consumer/Provider$ProviderState;");\r
-                return env->GetStaticObjectField(g_cls_ProviderState, fieldID);\r
+                providerState = env->GetStaticObjectField(g_cls_ProviderState, fieldID);\r
+                break;\r
             }\r
         case OIC::Service::NSProviderState::TOPIC:\r
             {\r
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_ProviderState,\r
                                           "TOPIC", "Lorg/iotivity/service/ns/consumer/Provider$ProviderState;");\r
-                return env->GetStaticObjectField(g_cls_ProviderState, fieldID);\r
+                providerState = env->GetStaticObjectField(g_cls_ProviderState, fieldID);\r
+                break;\r
             }\r
         case OIC::Service::NSProviderState::STOPPED:\r
             {\r
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_ProviderState,\r
                                           "STOPPED", "Lorg/iotivity/service/ns/consumer/Provider$ProviderState;");\r
-                return env->GetStaticObjectField(g_cls_ProviderState, fieldID);\r
+                providerState = env->GetStaticObjectField(g_cls_ProviderState, fieldID);\r
+                break;\r
             }\r
         default:\r
-            return NULL;\r
+            {\r
+                providerState = NULL;\r
+                break;\r
+            }\r
     }\r
     LOGD ("ConsumerService_getJavaProviderState - OUT");\r
-    return NULL;\r
+    return providerState;\r
 }\r
 \r
 jobject getJavaSyncType(JNIEnv *env, OIC::Service::NSSyncInfo::NSSyncType nsType)\r
@@ -117,32 +125,39 @@ jobject getJavaSyncType(JNIEnv *env, OIC::Service::NSSyncInfo::NSSyncType nsType
         LOGE ("Failed to Get ObjectClass for SyncType");\r
         return NULL;\r
     }\r
+    jobject syncType = NULL;\r
     switch (nsType)\r
     {\r
         case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_UNREAD:\r
             {\r
                 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,\r
                                           "UNREAD", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");\r
-                return env->GetStaticObjectField(cls_SyncType, fieldID);\r
+                syncType = env->GetStaticObjectField(cls_SyncType, fieldID);\r
+                break;\r
             }\r
         case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ :\r
             {\r
                 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,\r
                                           "READ", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");\r
-                return env->GetStaticObjectField(cls_SyncType, fieldID);\r
+                syncType = env->GetStaticObjectField(cls_SyncType, fieldID);\r
+                break;\r
             }\r
         case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED :\r
             {\r
                 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,\r
                                           "DELETED", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");\r
-                return env->GetStaticObjectField(cls_SyncType, fieldID);\r
+                syncType = env->GetStaticObjectField(cls_SyncType, fieldID);\r
+                break;\r
             }\r
         default:\r
-            return NULL;\r
+            {\r
+                syncType = NULL;\r
+                break;\r
+            }\r
     }\r
 \r
     LOGD ("ConsumerService_getJavaSyncType - OUT");\r
-    return NULL;\r
+    return syncType;\r
 }\r
 \r
 jobject getJavaTopicState(JNIEnv *env, OIC::Service::NSTopic::NSTopicState nsState)\r
@@ -156,6 +171,7 @@ jobject getJavaTopicState(JNIEnv *env, OIC::Service::NSTopic::NSTopicState nsSta
         LOGE ("Failed to Get ObjectClass for TopicState Type");\r
         return NULL;\r
     }\r
+    jobject topicState = NULL;\r
 \r
     switch (nsState)\r
     {\r
@@ -163,20 +179,25 @@ jobject getJavaTopicState(JNIEnv *env, OIC::Service::NSTopic::NSTopicState nsSta
             {\r
                 static jfieldID fieldID = env->GetStaticFieldID(cls_topicState,\r
                                           "UNSUBSCRIBED", "Lorg/iotivity/service/ns/common/Topic$TopicState;");\r
-                return env->GetStaticObjectField(cls_topicState, fieldID);\r
+                topicState = env->GetStaticObjectField(cls_topicState, fieldID);\r
+                break;\r
             }\r
         case OIC::Service::NSTopic::NSTopicState::SUBSCRIBED:\r
             {\r
                 static jfieldID fieldID = env->GetStaticFieldID(cls_topicState,\r
                                           "SUBSCRIBED", "Lorg/iotivity/service/ns/common/Topic$TopicState;");\r
-                return env->GetStaticObjectField(cls_topicState, fieldID);\r
+                topicState = env->GetStaticObjectField(cls_topicState, fieldID);\r
+                break;\r
             }\r
         default:\r
-            return NULL;\r
+            {\r
+                topicState = NULL;\r
+                break;\r
+            }\r
     }\r
 \r
     LOGD ("ConsumerService_getJavaTopicState - OUT");\r
-    return NULL;\r
+    return topicState;\r
 }\r
 \r
 jobject getJavaTopicsList(JNIEnv *env, OIC::Service::NSTopicsList *topicList)\r
@@ -437,37 +458,45 @@ jobject getJavaProvider(JNIEnv *env, OIC::Service::NSProvider *provider)
 jobject getJavaMessageType(JNIEnv *env, OIC::Service::NSMessage::NSMessageType type)\r
 {\r
     LOGD ("ConsumerService_getJavaMessageType - IN");\r
+    jobject messageType = NULL;\r
     switch (type)\r
     {\r
         case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_ALERT:\r
             {\r
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,\r
                                           "ALERT", "Lorg/iotivity/service/ns/common/Message$MessageType;");\r
-                return env->GetStaticObjectField(g_cls_Message_Type, fieldID);\r
+                messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);\r
+                break;\r
             }\r
         case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_NOTICE:\r
             {\r
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,\r
                                           "NOTICE", "Lorg/iotivity/service/ns/common/Message$MessageType;");\r
-                return env->GetStaticObjectField(g_cls_Message_Type, fieldID);\r
+                messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);\r
+                break;\r
             }\r
         case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_EVENT:\r
             {\r
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,\r
                                           "EVENT", "Lorg/iotivity/service/ns/common/Message$MessageType;");\r
-                return env->GetStaticObjectField(g_cls_Message_Type, fieldID);\r
+                messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);\r
+                break;\r
             }\r
         case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_INFO:\r
             {\r
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,\r
                                           "INFO", "Lorg/iotivity/service/ns/common/Message$MessageType;");\r
-                return env->GetStaticObjectField(g_cls_Message_Type, fieldID);\r
+                messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);\r
+                break;\r
             }\r
         default:\r
-            return NULL;\r
+            {\r
+                messageType = NULL;\r
+                break;\r
+            }\r
     }\r
     LOGD ("ConsumerService_getJavaMessageType - OUT");\r
-    return NULL;\r
+    return messageType;\r
 }\r
 \r
 jobject getJavaMessage(JNIEnv *env, OIC::Service::NSMessage *message)\r
index 57ca8e7..e227737 100755 (executable)
@@ -342,37 +342,45 @@ OIC::Service::NSMessage *getNativeMessage(JNIEnv *env, jobject jMsg)
 jobject getJavaMessageType(JNIEnv *env, OIC::Service::NSMessage::NSMessageType type)
 {
     LOGD ("JNIProviderService: getJavaMessageType - IN");
+    jobject messageType = NULL;
     switch (type)
     {
         case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_ALERT:
             {
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
                                           "ALERT", "Lorg/iotivity/service/ns/common/Message$MessageType;");
-                return env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                break;
             }
         case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_NOTICE:
             {
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
                                           "NOTICE", "Lorg/iotivity/service/ns/common/Message$MessageType;");
-                return env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                break;
             }
         case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_EVENT:
             {
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
                                           "EVENT", "Lorg/iotivity/service/ns/common/Message$MessageType;");
-                return env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                break;
             }
         case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_INFO:
             {
                 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
                                           "INFO", "Lorg/iotivity/service/ns/common/Message$MessageType;");
-                return env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);
+                break;
             }
         default:
-            return NULL;
+            {
+                messageType = NULL;
+                break;
+            }
     }
     LOGD ("JNIProviderService: getJavaMessageType - OUT");
-    return NULL;
+    return messageType;
 }
 
 jobject getJavaMessage(JNIEnv *env, OIC::Service::NSMessage *message)
@@ -550,6 +558,7 @@ jobject getJavaTopicState(JNIEnv *env, OIC::Service::NSTopic::NSTopicState nsSta
         LOGE ("Failed to Get ObjectClass for TopicState Type");
         return NULL;
     }
+    jobject topicState = NULL;
 
     switch (nsState)
     {
@@ -557,21 +566,25 @@ jobject getJavaTopicState(JNIEnv *env, OIC::Service::NSTopic::NSTopicState nsSta
             {
                 static jfieldID fieldID = env->GetStaticFieldID(cls_topicState,
                                           "UNSUBSCRIBED", "Lorg/iotivity/service/ns/common/Topic$TopicState;");
-                return env->GetStaticObjectField(cls_topicState, fieldID);
+                topicState = env->GetStaticObjectField(cls_topicState, fieldID);
+                break;
             }
         case OIC::Service::NSTopic::NSTopicState::SUBSCRIBED:
             {
                 static jfieldID fieldID = env->GetStaticFieldID(cls_topicState,
                                           "SUBSCRIBED", "Lorg/iotivity/service/ns/common/Topic$TopicState;");
-                return env->GetStaticObjectField(cls_topicState, fieldID);
+                topicState = env->GetStaticObjectField(cls_topicState, fieldID);
+                break;
             }
         default:
-            return NULL;
-
+            {
+                topicState = NULL;
+                break;
+            }
     }
 
     LOGD("JNIProviderService: getJavaTopicState - OUT");
-    return NULL;
+    return topicState;
 }
 
 jobject getJavaTopicsList(JNIEnv *env, OIC::Service::NSTopicsList *topicList)
@@ -625,32 +638,39 @@ jobject getJavaSyncType(JNIEnv *env, OIC::Service::NSSyncInfo::NSSyncType nsType
         LOGE ("Failed to Get ObjectClass for SyncType");
         return NULL;
     }
+    jobject syncType = NULL;
     switch (nsType)
     {
         case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_UNREAD:
             {
                 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
                                           "UNREAD", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
-                return env->GetStaticObjectField(cls_SyncType, fieldID);
+                syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
+                break;
             }
         case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ :
             {
                 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
                                           "READ", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
-                return env->GetStaticObjectField(cls_SyncType, fieldID);
+                syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
+                break;
             }
         case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED :
             {
                 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
                                           "DELETED", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
-                return env->GetStaticObjectField(cls_SyncType, fieldID);
+                syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
+                break;
             }
         default:
-            return NULL;
+            {
+                syncType = NULL;
+                break;
+            }
     }
 
     LOGD ("JNIProviderService: getJavaSyncType - OUT");
-    return NULL;
+    return syncType;
 }
 
 
index 37b2305..48a1e76 100755 (executable)
@@ -89,7 +89,10 @@ namespace OIC
                         auto discoveredCallback = NSConsumerService::getInstance()->getProviderDiscoveredCb();\r
                         discoveredCallback(oldProvider);\r
                         auto changeCallback = oldProvider->getProviderStateReceivedCb();\r
-                        changeCallback(prevState);\r
+                        if (changeCallback != NULL)\r
+                        {\r
+                            changeCallback(prevState);\r
+                        }\r
                     }\r
                 }\r
                 else if (state == NS_DENY)\r