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
diff --git a/src/lib/support/JniReferences.cpp b/src/lib/support/JniReferences.cpp
index 021f13c..3e1c8bd 100644
--- a/src/lib/support/JniReferences.cpp
+++ b/src/lib/support/JniReferences.cpp
@@ -310,8 +310,8 @@
{
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);