Skip to content

Commit 6654bc2

Browse files
committed
Cope with implementation inconsistencies in AttachCurrentThread
1 parent b5e3d06 commit 6654bc2

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

include/jni/functions.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,23 @@ namespace jni
588588

589589
inline UniqueEnv AttachCurrentThread(JavaVM& vm)
590590
{
591+
// Some implementations type the parameter as JNIEnv**, others as void**.
592+
// See https://bugs.openjdk.java.net/browse/JDK-6569899
593+
struct JNIEnvCast
594+
{
595+
void** operator()(JNIEnv** env, jint (JavaVM::*)(void**, void*))
596+
{
597+
return reinterpret_cast<void**>(env);
598+
}
599+
600+
JNIEnv** operator()(JNIEnv** env, jint (JavaVM::*)(JNIEnv**, void*))
601+
{
602+
return env;
603+
}
604+
};
605+
591606
JNIEnv* result;
592-
CheckErrorCode(vm.AttachCurrentThread(&result, nullptr));
607+
CheckErrorCode(vm.AttachCurrentThread(JNIEnvCast()(&result, &JavaVM::AttachCurrentThread), nullptr));
593608
return UniqueEnv(result, JNIEnvDeleter(vm));
594609
}
595610

0 commit comments

Comments
 (0)