Name: js151677 Date: 08/04/2004
FULL PRODUCT VERSION :
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [版本 5.1.2600]
(^^ it is the chinese version of XP)
A DESCRIPTION OF THE PROBLEM :
A simple drag operation on a customized JComponent causes a "FATAL ERROR" when we run the JVM with the option -Xcheck:jni ... here is the complete error message :
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:262)
at java.lang.Thread.run(Thread.java:534)
The bug can be reproduced using the "LabelDnD" demo on the page http://java.sun.com/docs/books/tutorial/uiswing/misc/example-1dot4/index.html#LabelDnD
The same bug appear on my reduiced program (that I copy in the "Step to reproduce section")
When I don't use the "-Xcheck:jni" option, my program randomly crash my IDE badly when I am using another native library (jogl), so I think the DnD corrupt the state of the JVM in a way.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I have 2 programs that produce the same bug. Here is the first one :
import java.awt.event.*;
import javax.swing.*;
public class BugComponent extends JLabel {
public BugComponent()
{
setText("Drag me and Bug");
setTransferHandler(new TransferHandler("text"));
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
JComponent component = (JComponent) event.getSource();
TransferHandler handler = component.getTransferHandler();
handler.exportAsDrag(component, event, TransferHandler.COPY);
}
});
}
public static void main(String[] args)
{
JFrame f = new JFrame();
f.getContentPane().add(new BugComponent());
f.setSize(100, 100);
f.show();
}
}
The command line should be :
java -Xcheck:jni BugComponent
.. then, drag the label and the JVM stop and the message :
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:262)
at java.lang.Thread.run(Thread.java:534)
... is displayed in the console
The other program that produce the same effect is the "LabelDnD" demo from http://java.sun.com/docs/books/tutorial/uiswing/misc/example-1dot4/index.html#LabelDnD
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The JVM should not have any reason to crash. In the worst case (= if the java program is not right), it could be better if an explicit exception were thrown.
ACTUAL -
The DnD causes a FATAL ERROR. If the "-Xcheck:jni" option is not used, the JVM state is corrupted and crash later, sometime, randomly, every 5 minutes of intensive DnD use when using another native library (a GLFrame from jogl).
ERROR MESSAGES/STACK TRACES THAT OCCUR :
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:262)
at java.lang.Thread.run(Thread.java:534)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.event.*;
import javax.swing.*;
public class BugComponent extends JLabel {
public BugComponent()
{
setText("Drag me and Bug");
setTransferHandler(new TransferHandler("text"));
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
JComponent component = (JComponent) event.getSource();
TransferHandler handler = component.getTransferHandler();
handler.exportAsDrag(component, event, TransferHandler.COPY);
}
});
}
public static void main(String[] args)
{
JFrame f = new JFrame();
f.getContentPane().add(new BugComponent());
f.setSize(100, 100);
f.show();
}
}
The command line should be :
java -Xcheck:jni BugComponent
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None found.
(Incident Review ID: 295664)
======================================================================