Skip to content

Commit f69e9b2

Browse files
[jnigen] Fix getID bug (#1029)
jniEnv could be null before calling attachThread, even for getting the function pointer.
1 parent 7c3fe5a commit f69e9b2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pkgs/jni/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
- `JObject`s now check the types using `instanceof` in debug mode when using
4747
`castTo`.
4848

49+
## 0.7.3
50+
51+
- Fixed a bug where `get(Static)MethodID` and `get(Static)FieldID` could access
52+
null and throw.
53+
4954
## 0.7.2
5055

5156
- Fixed a bug where reading non-null terminated strings would overflow.

pkgs/jni/src/dartjni.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,25 +209,28 @@ static inline JniPointerResult _getId(MemberGetter getter,
209209
char* name,
210210
char* sig) {
211211
JniPointerResult result = {NULL, NULL};
212-
attach_thread();
213212
result.value = getter(jniEnv, cls, name, sig);
214213
result.exception = check_exception();
215214
return result;
216215
}
217216

218217
JniPointerResult getMethodID(jclass cls, char* name, char* sig) {
218+
attach_thread();
219219
return _getId((MemberGetter)(*jniEnv)->GetMethodID, cls, name, sig);
220220
}
221221

222222
JniPointerResult getStaticMethodID(jclass cls, char* name, char* sig) {
223+
attach_thread();
223224
return _getId((MemberGetter)(*jniEnv)->GetStaticMethodID, cls, name, sig);
224225
}
225226

226227
JniPointerResult getFieldID(jclass cls, char* name, char* sig) {
228+
attach_thread();
227229
return _getId((MemberGetter)(*jniEnv)->GetFieldID, cls, name, sig);
228230
}
229231

230232
JniPointerResult getStaticFieldID(jclass cls, char* name, char* sig) {
233+
attach_thread();
231234
return _getId((MemberGetter)(*jniEnv)->GetStaticFieldID, cls, name, sig);
232235
}
233236

0 commit comments

Comments
 (0)