Skip to content

Commit e402b96

Browse files
authored
Fix JniReferences::GetOptionalValue (#36682)
* Fix JniReferences::GetOptionalValue It's possible the optional is not of class java/util/Optional so just use the object provided * fix formatting
1 parent 2474fc3 commit e402b96

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/lib/support/JniReferences.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ CHIP_ERROR JniReferences::GetOptionalValue(jobject optionalObj, jobject & option
310310
{
311311
JNIEnv * env = GetEnvForCurrentThread();
312312
VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT);
313-
jclass optionalCls = nullptr;
314-
ReturnErrorOnFailure(chip::JniReferences::GetInstance().GetLocalClassRef(env, "java/util/Optional", optionalCls));
313+
VerifyOrReturnError(optionalObj != nullptr, CHIP_JNI_ERROR_NULL_OBJECT);
314+
jclass optionalCls = env->GetObjectClass(optionalObj);
315315
jmethodID isPresentMethod = env->GetMethodID(optionalCls, "isPresent", "()Z");
316316
VerifyOrReturnError(isPresentMethod != nullptr, CHIP_JNI_ERROR_METHOD_NOT_FOUND);
317317
jboolean isPresent = optionalObj && env->CallBooleanMethod(optionalObj, isPresentMethod);

0 commit comments

Comments
 (0)