From 598cdff54c97cebdd8e1fcab79495b0802fa4d75 Mon Sep 17 00:00:00 2001 From: heguokai <275503077@qq.com> Date: Sat, 30 Aug 2025 15:14:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DSubscribeInfo=E9=87=8C?= =?UTF-8?q?=E9=9D=A2slotTypes=E5=8F=82=E6=95=B0=E7=BC=BA=E7=9C=81=E6=97=B6?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: heguokai <275503077@qq.com> --- frameworks/ets/ani/src/sts_common.cpp | 6 ++++-- frameworks/ets/ani/src/sts_subscribe_info.cpp | 10 ++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/frameworks/ets/ani/src/sts_common.cpp b/frameworks/ets/ani/src/sts_common.cpp index b6efeceab..e3ed4f9fe 100644 --- a/frameworks/ets/ani/src/sts_common.cpp +++ b/frameworks/ets/ani/src/sts_common.cpp @@ -340,11 +340,13 @@ ani_status GetPropertyEnumItemArray(ani_env *env, ani_object param, const char * ani_ref arrayObj = nullptr; ani_status status; ani_int length; - if ((status = GetPropertyRef(env, param, name, isUndefined, arrayObj)) != ANI_OK || - isUndefined == ANI_TRUE) { + if ((status = GetPropertyRef(env, param, name, isUndefined, arrayObj)) != ANI_OK) { ANS_LOGE("GetPropertyRef fail, status = %{public}d, isUndefind = %{public}d", status, isUndefined); return ANI_INVALID_ARGS; } + if (isUndefined == ANI_TRUE) { + return ANI_OK; + } status = env->Object_GetPropertyByName_Int(static_cast(arrayObj), "length", &length); if (status != ANI_OK) { ANS_LOGE("status: %{public}d", status); diff --git a/frameworks/ets/ani/src/sts_subscribe_info.cpp b/frameworks/ets/ani/src/sts_subscribe_info.cpp index 36289d573..042da4140 100644 --- a/frameworks/ets/ani/src/sts_subscribe_info.cpp +++ b/frameworks/ets/ani/src/sts_subscribe_info.cpp @@ -24,11 +24,17 @@ bool GetSlotTypes(ani_env *env, ani_object value, NotificationSubscribeInfo &inf { ani_boolean isUndefined = ANI_TRUE; std::vector slotTypesEnum = {}; - if (ANI_OK != GetPropertyEnumItemArray(env, value, "slotTypes", isUndefined, slotTypesEnum) - || isUndefined == ANI_TRUE || slotTypesEnum.empty()) { + if (ANI_OK != GetPropertyEnumItemArray(env, value, "slotTypes", isUndefined, slotTypesEnum)) { ANS_LOGE("GetPropertyEnumItemArray fail or undefined"); return false; } + if (isUndefined == ANI_TRUE) { + return true; + } + if (slotTypesEnum.empty()) { + ANS_LOGE("slotTypes is empty"); + return false; + } std::vector slotTypes = {}; for (auto slotTypeEnum : slotTypesEnum) { SlotType slotType = SlotType::OTHER; -- Gitee