MCPcopy Create free account
hub / github.com/AshampooSystems/boden / createEnv

Method createEnv

framework/foundation/platforms/android/src/java/Env.cpp:48–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46 }
47
48 void Env::createEnv()
49 {
50 if (_envIfKnown == nullptr) {
51 if (_globalVm == nullptr) {
52 throw std::runtime_error("bdn::java::Env used from unattached thread, but "
53 "global VM pointer not initialized.");
54 }
55
56 JNIEnv *env = nullptr;
57 bool mustDetachThread = false;
58 int getResult =
59 _globalVm->GetEnv((void **)&env, JNI_VERSION_1_6); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
60 if (getResult == JNI_EDETACHED) {
61 // thread is not yet attached to the VM. Attach it.
62 int attachResult = _globalVm->AttachCurrentThread(&env, nullptr);
63 if (attachResult != JNI_OK) {
64 throw std::runtime_error("Fatal error: unable to attach JNI to current "
65 "thread (JavaVM::AttachCurrentThread result " +
66 std::to_string(attachResult) + ").");
67 }
68
69 mustDetachThread = true;
70 } else if (getResult != JNI_OK) {
71 throw std::runtime_error("Fatal error: unable to get JNI env for current thread "
72 "(JNIEnv::GetEnv result " +
73 std::to_string(getResult) + ".");
74 }
75
76 setEnv(env, mustDetachThread);
77 }
78 }
79}

Callers

nothing calls this directly

Calls 2

GetEnvMethod · 0.80
AttachCurrentThreadMethod · 0.80

Tested by

no test coverage detected