United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6610244 modal dialog closes with fatal error if -Xcheck:jni is set
JDK-6610244 : modal dialog closes with fatal error if -Xcheck:jni is set

Details
Type:
Bug
Submit Date:
2007-09-27
Status:
Resolved
Updated Date:
2012-06-05
Project Name:
JDK
Resolved Date:
2008-05-15
Component:
client-libs
OS:
windows_vista,windows_xp,windows_2000,windows
Sub-Component:
java.awt
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u10,6u12,7
Fixed Versions:

Related Reports
Backport:
Backport:
Duplicate:
Duplicate:
Relates:

Sub Tasks

Description
Using JDK7 run sample with a modal dialog like Font2DTest from the jfc folder:
..\JDK7.0b19\bin\java -Xcheck:jni -jar Font2DTest.jar

Steps to reproduce:
1) Open File menu
2) select Print menu item
3) press Cancel button in the appeared dialog

FATAL ERROR in native method: Bad global or local ref passed to JNI
        at sun.awt.windows.WToolkit.eventLoop(Native Method)
        at sun.awt.windows.WToolkit.run(WToolkit.java:285)
        at java.lang.Thread.run(Thread.java:659)

Reproducible always. Not reproducible with JDK6.

                                    

Comments
EVALUATION

_endModal() function exits with error code.
                                     
2007-09-27
SUGGESTED FIX

--- awt_Window.cpp	2008-01-11 20:06:20.000000000 +0300
***************
*** 2143,2149 ****
  {
      TRY;
  
!     AwtWindow::wwindowPeerCls = cls;
      AwtWindow::getActiveWindowsMID =
          env->GetStaticMethodID(cls, "getActiveWindowHandles", "()[J");
      DASSERT(AwtWindow::getActiveWindowsMID != NULL);
--- 2143,2149 ----
  {
      TRY;
  
!     AwtWindow::wwindowPeerCls = (jclass)env->NewGlobalRef(cls);
      AwtWindow::getActiveWindowsMID =
          env->GetStaticMethodID(cls, "getActiveWindowHandles", "()[J");
      DASSERT(AwtWindow::getActiveWindowsMID != NULL);
                                     
2008-01-11
EVALUATION

I tracked the crash up to the place where we get the array of active windows in AwtDialog:
void AwtDialog::ModalActivateNextWindow(HWND dialogHWnd,
                                        jobject dialogTarget, jobject dialogPeer){
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
    jlongArray windows = (jlongArray)(env->CallStaticObjectMethod(AwtWindow::wwindowPeerCls, awtWindow::getActiveWindowsMID));

Seem that the AwtWindow::wwindowPeerCls member has Local instead of Global reference as its value. Searching the place where the assignment happens I found: 
Java_sun_awt_windows_WWindowPeer_initIDs(JNIEnv *env, jclass cls)
{
    TRY;
    AwtWindow::wwindowPeerCls = cls;
    AwtWindow::getActiveWindowsMID =...

Should wrap it into GlobalRef before using from the other thread.
Perhaps the change caused that code to be called on a different thread and caused this to happen went into early JDK7 build.
                                     
2008-01-11



Hardware and Software, Engineered to Work Together