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

Qt detaches JNI threads it didn't attach

    XMLWordPrintable

Details

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

    Description

      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);
       }

      Attachments

        For Gerrit Dashboard: QTBUG-45110
        # Subject Branch Project Status CR V

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes