Skip to content

Commit

Permalink
error ref
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed May 5, 2024
1 parent 3ebd4ef commit a2fed97
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions jmi.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* JMI: JNI Modern Interface
* Copyright (C) 2016-2023 Wang Bin - [email protected]
* Copyright (C) 2016-2024 Wang Bin - [email protected]
* https://github.com/wang-bin/JMI
* MIT License
*/
Expand Down Expand Up @@ -167,7 +167,7 @@ class JObject : public ClassTag
operator jclass() const { return classId();}
jobject id() const { return oid_; }
explicit operator bool() const { return !!oid_;}
string error() const {return error_;}
const string& error() const {return error_;}
JObject& reset(jobject obj = nullptr, JNIEnv *env = nullptr);

template<typename... Args>
Expand Down Expand Up @@ -275,7 +275,7 @@ class JObject : public ClassTag
}
private:
static jclass classId(JNIEnv* env = nullptr);
JObject& setError(string&& s) const {
JObject& setError(const string& s) const {
error_ = std::move(s);
return *const_cast<JObject*>(this);
}
Expand Down Expand Up @@ -980,8 +980,7 @@ JObject<CTag>& JObject<CTag>::reset(jobject obj, JNIEnv *env) {
if (!env)
return setError("Invalid JNIEnv");
}
if (oid_)
env->DeleteGlobalRef(oid_);
env->DeleteGlobalRef(oid_); // can be null
oid_ = nullptr;
if (obj) {
oid_ = env->NewGlobalRef(obj);
Expand Down

0 comments on commit a2fed97

Please sign in to comment.