Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-45110

Qt detaches JNI threads it didn't attach

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P1: Critical P1: Critical
    • 5.5.0 Beta
    • 5.4.1
    • QPA
    • None
    • Android
    • 6b19eec63190c385a465c29b1f811214c6257034

      Qt detaches threads that it did not attach which is an unexpected behaviour and may cause weird effects or crash in apps which also use non-Qt access to JNI. Also it crashes QCoreApplication-based app on Android (e.g. service or app without Qt GUI) with ART because QCoreApplication trashes thread storage in destructor before the thread has actually finished ant it causes ART to terminate application.

      The fix is trivial, just move 2 lines:

      --- a/qtbase/src/corelib/kernel/qjni.cpp
      +++ b/qtbase/src/corelib/kernel/qjni.cpp
      @@ -225,13 +225,9 @@ QJNIEnvironmentPrivate::QJNIEnvironmentPrivate()
               JavaVMAttachArgs args = { JNI_VERSION_1_6, qJniThreadName, Q_NULLPTR };
               if (vm->AttachCurrentThread(&jniEnv, &args) != JNI_OK)
                   return;
      +        if (!jniEnvTLS->hasLocalData())
      +            jniEnvTLS->setLocalData(new QJNIEnvironmentPrivateTLS);
           }
      -
      -    if (!jniEnv)
      -        return;
      -
      -    if (!jniEnvTLS->hasLocalData())
      -        jniEnvTLS->setLocalData(new QJNIEnvironmentPrivateTLS);
       }

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            stromme Christian
            thelivingone Sergey Galin
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes