Skip to content

Commit efe1bda

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

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
@@ -211,25 +211,28 @@ static inline JniPointerResult _getId(MemberGetter getter,
211211
char* name,
212212
char* sig) {
213213
JniPointerResult result = {NULL, NULL};
214-
attach_thread();
215214
result.value = getter(jniEnv, cls, name, sig);
216215
result.exception = check_exception();
217216
return result;
218217
}
219218

220219
JniPointerResult getMethodID(jclass cls, char* name, char* sig) {
220+
attach_thread();
221221
return _getId((MemberGetter)(*jniEnv)->GetMethodID, cls, name, sig);
222222
}
223223

224224
JniPointerResult getStaticMethodID(jclass cls, char* name, char* sig) {
225+
attach_thread();
225226
return _getId((MemberGetter)(*jniEnv)->GetStaticMethodID, cls, name, sig);
226227
}
227228

228229
JniPointerResult getFieldID(jclass cls, char* name, char* sig) {
230+
attach_thread();
229231
return _getId((MemberGetter)(*jniEnv)->GetFieldID, cls, name, sig);
230232
}
231233

232234
JniPointerResult getStaticFieldID(jclass cls, char* name, char* sig) {
235+
attach_thread();
233236
return _getId((MemberGetter)(*jniEnv)->GetStaticFieldID, cls, name, sig);
234237
}
235238

0 commit comments

Comments
 (0)