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

Win: Bad global or local ref passed to JNI when using -Xcheck:jni option

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • 8
    • 7u10
    • javafx
    • Windows 7 64-bit, JDK7u11

      When I use -Xcheck:jni on my swing application, there is this fatal error :

      FATAL ERROR in native method: Bad global or local ref passed to JNI
      at com.sun.glass.ui.win.WinScreen._getMainScreen(Native Method)
      at com.sun.glass.ui.win.WinScreen.getMainScreen_impl(WinScreen.java:43)
      at com.sun.glass.ui.win.WinApplication.staticScreen_getMainScreen(WinApplication.java:151)
      at com.sun.glass.ui.Screen.getMainScreen(Screen.java:15)
      at com.sun.javafx.tk.quantum.QuantumToolkit.getPrimaryScreen(QuantumToolkit.java:594)
      at javafx.stage.Screen.updateConfiguration(Screen.java:102)
      at javafx.stage.Screen.checkDirty(Screen.java:97)
      at javafx.stage.Screen.getPrimary(Screen.java:176)
      at javafx.stage.Window.centerOnScreen(Window.java:224)
      at javafx.stage.Window$10.invalidated(Window.java:731)
      at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:127)
      at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:161)
      at javafx.stage.Window.setShowing(Window.java:782)
      at javafx.stage.Window.show(Window.java:797)
      at com.sun.javafx.stage.EmbeddedWindow.show(EmbeddedWindow.java:57)
      at javafx.embed.swing.JFXPanel.setSceneImpl(JFXPanel.java:278)
      at javafx.embed.swing.JFXPanel.setScene(JFXPanel.java:245)
      at Tests.Test.initFX(Test.java:41)
      at Tests.Test.access$0(Test.java:38)
      at Tests.Test$1.run(Test.java:33)
      at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
      at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
      at java.lang.Thread.run(Thread.java:722)

      It seems JNI doesn't like you initialize the JNI in the main thread and use the same objects in "Platform.runLater()" thread.
      The error happened only with -Xcheck:jni option. But I guess there is a good reason it stopped.
      I can reproduce it with the following example from Oracle's website (http://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm)

      Thanks helping me,
      Alex

      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.paint.Color;
      import javafx.scene.text.Font;
      import javafx.scene.text.Text;
      import javax.swing.JFrame;
      import javax.swing.SwingUtilities;

      public class Test {

          private static void initAndShowGUI() {
              // This method is invoked on the EDT thread
              JFrame frame = new JFrame("Swing and JavaFX");
              final JFXPanel fxPanel = new JFXPanel();
              frame.add(fxPanel);
              frame.setSize(300, 200);
              frame.setVisible(true);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              Platform.runLater(new Runnable() {
                  @Override
                  public void run() {
                  initFX(fxPanel);
                  }
             });
          }

          private static void initFX(JFXPanel fxPanel) {
              // This method is invoked on the JavaFX thread
              Scene scene = createScene();
              fxPanel.setScene(scene);
          }

          private static Scene createScene() {
              Group root = new Group();
              Scene scene = new Scene(root, Color.ALICEBLUE);
              Text text = new Text();
              text.setX(40);
              text.setY(100);
              text.setFont(new Font(25));
              text.setText("Welcome JavaFX!");
              root.getChildren().add(text);
              return (scene);
          }
          
          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                  initAndShowGUI();
                  }
              });
          }
      }

            pchelko Petr Pchelko (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: