Skip to content

Commit

Permalink
KeepMember OsObject.notifyChangeListeners
Browse files Browse the repository at this point in the history
- Fix #4461.
- Use release assertion when finding java method.
  • Loading branch information
beeender committed Apr 11, 2017
1 parent f733087 commit c9380bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 3.1.2 (YYYY-MM-DD)

### Bug Fixes

* Crash caused by JNI couldn't find `OsObject.notifyChangeListeners` when ProGurad is enabled (#4461).

This comment has been minimized.

Copy link
@Zhuinden

Zhuinden Apr 11, 2017

Contributor

ProGuard


## 3.1.1 (2017-04-07)

### Deprecated
Expand Down
6 changes: 3 additions & 3 deletions realm/realm-library/src/main/cpp/jni_util/java_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ JavaMethod::JavaMethod(JNIEnv* env, jclass cls, const char* method_name, const c
m_method_id = env->GetMethodID(cls, method_name, signature);
}

REALM_ASSERT_DEBUG(m_method_id != nullptr);
REALM_ASSERT_RELEASE(m_method_id != nullptr);
}

JavaMethod::JavaMethod(JNIEnv* env, jobject obj, const char* method_name, const char* signature)
{
jclass cls = env->GetObjectClass(obj);
m_method_id = env->GetMethodID(cls, method_name, signature);
REALM_ASSERT_DEBUG(m_method_id != nullptr);
REALM_ASSERT_RELEASE(m_method_id != nullptr);
env->DeleteLocalRef(cls);
}

JavaMethod::JavaMethod(JNIEnv* env, const char* class_name, const char* method_name, const char* signature,
bool static_method)
{
jclass cls = env->FindClass(class_name);
REALM_ASSERT_DEBUG(cls != nullptr);
REALM_ASSERT_RELEASE(cls != nullptr);
if (static_method) {
m_method_id = env->GetStaticMethodID(cls, method_name, signature);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/**
* Java wrapper for Object Store's {@code Object} class. Currently it is only used for object notifications.
*/
@KeepMember
public class OsObject implements NativeObject {

private static class OsObjectChangeSet implements ObjectChangeSet {
Expand Down Expand Up @@ -143,6 +144,7 @@ public void setObserverPairs(ObserverPairList<ObjectObserverPair> pairs) {

// Called by JNI
@SuppressWarnings("unused")
@KeepMember
private void notifyChangeListeners(String[] changedFields) {
observerPairs.foreach(new Callback(changedFields));
}
Expand Down

0 comments on commit c9380bd

Please sign in to comment.