Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8275494

[gtk3] Desktop.open() doesn't use gtk_main()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • 8, 11.0.12, 17, 18
    • client-libs
    • gtk 3 >= 3.24.30

    • generic
    • linux

      This bug was originally reported here:
      https://bugzilla.redhat.com/show_bug.cgi?id=1961119

      The issue is that in some circumstances when Desktop.getDesktop().open(File) is being called there might not be any gtk_main() running resulting in the platform's associated application to actually handle opening that file to not show until the Java application actually ends running (exits).

      This code in awt_Desktop.c is being used:

      /*
       * Class: sun_awt_X11_XDesktopPeer
       * Method: gnome_url_show
       * Signature: (Ljava/lang/[B;)Z
       */
      JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_gnome_1url_1show
        (JNIEnv *env, jobject obj, jbyteArray url_j)
      {
          gboolean success = FALSE;
          const gchar* url_c;

          url_c = (char*)(*env)->GetByteArrayElements(env, url_j, NULL);
          if (url_c == NULL) {
              if (!(*env)->ExceptionCheck(env)) {
                  JNU_ThrowOutOfMemoryError(env, 0);
              }
              return JNI_FALSE;
          }

          if (gtk_has_been_loaded) {
              gtk->gdk_threads_enter();
              success = gtk->gtk_show_uri(NULL, url_c, GDK_CURRENT_TIME, NULL);
              gtk->gdk_threads_leave();
          }

      In particular:

              gtk->gdk_threads_enter();
              success = gtk->gtk_show_uri(NULL, url_c, GDK_CURRENT_TIME, NULL);
              gtk->gdk_threads_leave();

      which fails to call gtk->gtk_main(). This breaks on systems with >= gtk3-3.24.30, for example on Fedora 34.

      Steps to reproduce:

      $ java TestDesktop /path/to/file.pdf

      Actual results:
      10 second delay, then the app exits and the file is shown.

      Expected results:
      No delay, app is opened to show the file immediately.

      Additional info:

      Running the reproducer with:
      $ java TestDesktop --dialog /path/to/file.pdf

      ... shows the PDF right away because a FileDialog is being opened too which has a gtk_main() call associated with it.

            abhiscxk Abhishek Kumar
            sgehwolf Severin Gehwolf
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: