Skip to content

Commit

Permalink
Fix JniReferences::GetOptionalValue (#36682)
Browse files Browse the repository at this point in the history
* Fix JniReferences::GetOptionalValue

It's possible the optional is not of class java/util/Optional so just use the object provided

* fix formatting
  • Loading branch information
achaulk-goog authored Nov 29, 2024
1 parent 2474fc3 commit e402b96
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/support/JniReferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ CHIP_ERROR JniReferences::GetOptionalValue(jobject optionalObj, jobject & option
{
JNIEnv * env = GetEnvForCurrentThread();
VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT);
jclass optionalCls = nullptr;
ReturnErrorOnFailure(chip::JniReferences::GetInstance().GetLocalClassRef(env, "java/util/Optional", optionalCls));
VerifyOrReturnError(optionalObj != nullptr, CHIP_JNI_ERROR_NULL_OBJECT);
jclass optionalCls = env->GetObjectClass(optionalObj);
jmethodID isPresentMethod = env->GetMethodID(optionalCls, "isPresent", "()Z");
VerifyOrReturnError(isPresentMethod != nullptr, CHIP_JNI_ERROR_METHOD_NOT_FOUND);
jboolean isPresent = optionalObj && env->CallBooleanMethod(optionalObj, isPresentMethod);
Expand Down

0 comments on commit e402b96

Please sign in to comment.