From d87c07444c720b539b1385438a0858bd2156db98 Mon Sep 17 00:00:00 2001 From: Amit Jain Date: Wed, 25 Jan 2023 12:11:57 -0800 Subject: [PATCH] Use JniUtfString. --- .../android/java/ContentAppCommandDelegate.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/tv-app/android/java/ContentAppCommandDelegate.cpp b/examples/tv-app/android/java/ContentAppCommandDelegate.cpp index eededac39f5d4b..05763b6e09883e 100644 --- a/examples/tv-app/android/java/ContentAppCommandDelegate.cpp +++ b/examples/tv-app/android/java/ContentAppCommandDelegate.cpp @@ -82,10 +82,9 @@ void ContentAppCommandDelegate::InvokeCommand(CommandHandlerInterface::HandlerCo FormatResponseData(handlerContext, "{\"value\":{}}"); return; } - const char * respStr = env->GetStringUTFChars(resp, 0); - ChipLogProgress(Zcl, "ContentAppCommandDelegate::InvokeCommand got response %s", respStr); - FormatResponseData(handlerContext, respStr); - env->ReleaseStringUTFChars(resp, respStr); + JniUtfString respStr(env, resp); + ChipLogProgress(Zcl, "ContentAppCommandDelegate::InvokeCommand got response %s", respStr.c_str()); + FormatResponseData(handlerContext, respStr.c_str()); env->DeleteLocalRef(resp); } else @@ -115,15 +114,15 @@ Status ContentAppCommandDelegate::InvokeCommand(EndpointId epId, ClusterId clust } else { - const char * respStr = env->GetStringUTFChars(resp, 0); - ChipLogProgress(Zcl, "ContentAppCommandDelegate::InvokeCommand got response %s", respStr); + JniUtfString respStr(env, resp); + ChipLogProgress(Zcl, "ContentAppCommandDelegate::InvokeCommand got response %s", respStr.c_str()); Json::Reader reader; - if (!reader.parse(respStr, value)) + if (!reader.parse(respStr.c_str(), value)) { + env->DeleteLocalRef(resp); return Protocols::InteractionModel::Status::Failure; } - env->ReleaseStringUTFChars(resp, respStr); } env->DeleteLocalRef(resp);