United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-5076963 : JNI bugs in sun.awt.windows.WToolkit.eventLoop()

Details
Type:
Bug
Submit Date:
2004-07-22
Status:
Resolved
Updated Date:
2012-10-09
Project Name:
JDK
Resolved Date:
2004-09-28
Component:
client-libs
OS:
windows_nt,windows_xp,windows_2000
Sub-Component:
java.awt
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.2,1.4.2_07,5.0,6
Fixed Versions:
5.0u1 (01)

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

Sub Tasks

Description
Name: rmT116609			Date: 07/21/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b57)
Java HotSpot(TM) Client VM (build 1.5.0-beta3-b57, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Hi,

    There are numerous JNI bugs in sun.awt.windows.WToolkit.eventLoop() both in JDK 1.4.2 and JDK 5.0 beta 3 releases. If you run the attached testcase with -Xcheck:jni, then close the JFrame that pops up you will get:

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:269)
        at java.lang.Thread.run(Thread.java:595)

     This is a minimalistic example of the sort of errors I am getting in my more-complex application. The problem is that in my more complicated application this bug actually causes hangs/crashes to appear at random. . 


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;

public class Test
{
  public static void main(String[] args)
  {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setVisible( true );
  }
}
---------- END SOURCE ----------
(Incident Review ID: 286708) 
======================================================================

                                    

Comments
SUGGESTED FIX

Name: ag153227			Date: 08/02/2004


A global reference may be passed to another thread instead of the
local reference, but since the argument 'activeWindow' is not used
in essence, I propose not to pass 'activeWindow' to another thread
at all.


--- awt_KeyboardFocusManager.cpp        Mon Aug  2 18:05:44 2004
***************
*** 127,133 ****
       TRY;

       AwtToolkit::GetInstance().InvokeFunction
! 
((void*(*)(void*))AwtComponent::ClearGlobalFocusOwner,activeWindow);

       CATCH_BAD_ALLOC;
   }
--- 127,133 ----
       TRY;

       AwtToolkit::GetInstance().InvokeFunction
!         ((void*(*)(void))AwtComponent::ClearGlobalFocusOwner);

       CATCH_BAD_ALLOC;
   }



--- awt_Component.h     Mon Aug  2 17:55:31 2004
***************
*** 574,580 ****

       static void * GetNativeFocusOwner();
       static void * GetNativeFocusedWindow();
!     static void   ClearGlobalFocusOwner(jobject activeWindow);

       /*
        * HWND, AwtComponent and Java Peer interaction
--- 574,580 ----

       static void * GetNativeFocusOwner();
       static void * GetNativeFocusedWindow();
!     static void   ClearGlobalFocusOwner();

       /*
        * HWND, AwtComponent and Java Peer interaction



--- awt_Component.cpp   Mon Aug  2 18:24:19 2004
***************
*** 4919,4930 ****
       return (comp != NULL) ? comp->GetTargetAsGlobalRef(env) : NULL;
   }
   void
! AwtComponent::ClearGlobalFocusOwner(jobject activeWindow) {
       if (AwtComponent::sm_focusOwner != NULL) {
-         JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
-         if (activeWindow != NULL) {
-             env->DeleteLocalRef(activeWindow);
-         }
           ::SetFocus(NULL);
       }
   }
--- 4919,4926 ----
       return (comp != NULL) ? comp->GetTargetAsGlobalRef(env) : NULL;
   }
   void
! AwtComponent::ClearGlobalFocusOwner() {
       if (AwtComponent::sm_focusOwner != NULL) {
           ::SetFocus(NULL);
       }
   }


###@###.###


======================================================================
                                     
2004-09-28
EVALUATION

We will investigate this in next release.
###@###.### 2004-07-23

It's too late for Tiger, we will try to fix it in first update release.
###@###.### 2004-07-29

###@###.### 2004-07-29

Name: ag153227			Date: 08/02/2004


The native method
Java_sun_awt_KeyboardFocusManagerPeerImpl_clearNativeGlobalFocusOwner
     (JNIEnv *env, jobject self, jobject activeWindow),
which is called on the event dispatch thread, passes (via
SendMesage()) the JNI local reference 'activeWindow' to the toolkit
thread, to the method AwtComponent::ClearGlobalFocusOwner().
Then the local reference is deleted in the method
AwtComponent::ClearGlobalFocusOwner(), and this causes the error
since local references are only valid in the thread in which they are
created.

###@###.###
======================================================================

Name: ag153227			Date: 08/04/2004

This bug isn't reproducible with mantis because the following tiger
fix introduced it:

awt_KeyboardFocusManager.cpp
D 1.11 03/07/23 13:57:32 bg139121 14 13 00010/00022/00124
Fixed problem found during PIT testing, caused by renaming of some
shared native functions.

awt_Component.cpp
D 1.334 03/07/23 13:57:30 bg139121 583 580      00001/00004/06625
Fixed problem found during PIT testing, caused by renaming of some
shared native functions.

awt_Component.h
D 1.166 03/07/23 13:57:31 bg139121 237 234      00001/00001/00760
Fixed problem found during PIT testing, caused by renaming of some
shared native functions.

###@###.###
======================================================================
###@###.### 2004-08-04
###@###.### 2004-08-04
                                     
2004-09-28
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
1.5.0_01
mustang

FIXED IN:
1.5.0_01
mustang

INTEGRATED IN:
1.5.0_01


                                     
2004-09-28



Hardware and Software, Engineered to Work Together