JDK-5076963 : JNI bugs in sun.awt.windows.WToolkit.eventLoop()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.2,1.4.2_07,5.0,6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt,windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2004-07-22
  • Updated: 2012-10-09
  • Resolved: 2004-09-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6
1.4.2_09Resolved 6Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
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
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
28-09-2004

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
28-09-2004

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); } } ###@###.### ======================================================================
28-09-2004