Dinesh966 / jnativehook

Automatically exported from code.google.com/p/jnativehook
0 stars 0 forks source link

Exception Thrown when calling unregisterNativeHook #12

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi Alex, I've started playing with JNativeHook again and I'm seeing the 
following issue with the 1.1.0 RC2.

I'm running the executable Jar that ships with JNativeHook from the command 
line using JNativeHook-1.1.0_rc2 on Windows7 using the following command...

java -jar JNativeHook.jar

It runs fine, but when you close the window the following exception is 
displayed:

org.jnativehook.NativeHookException: Native thread stop failure
        at org.jnativehook.GlobalScreen.unregisterNativeHook(Native Method)
        at org.jnativehook.example.NativeHookDemo.windowClosed(Unknown Source)
        at java.awt.Window.processWindowEvent(Window.java:1868)
        at javax.swing.JFrame.processWindowEvent(JFrame.java:274)
        at java.awt.Window.processEvent(Window.java:1823)
        at java.awt.Component.dispatchEventImpl(Component.java:4652)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Window.dispatchEventImpl(Window.java:2478)
        at java.awt.Component.dispatchEvent(Component.java:4482)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
        at java.awt.EventQueue.access$000(EventQueue.java:85)
        at java.awt.EventQueue$1.run(EventQueue.java:603)
        at java.awt.EventQueue$1.run(EventQueue.java:601)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
        at java.awt.EventQueue$2.run(EventQueue.java:617)
        at java.awt.EventQueue$2.run(EventQueue.java:615)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

I tried a test using: JNativeHook-1.0.2288
and that runs without throwing the exception.

On what operating system?
I'm running Windows7 64 bit - Service Pack 1
I'm running as an Administrator

Original issue reported on code.google.com by awbra...@gmail.com on 12 Jun 2012 at 2:19

GoogleCodeExporter commented 8 years ago
It could be one of two problems.  Either your JRE is calling windowClosed() 
from outside of the AWT Event dispatch thread or there is a to much 
optimization bug in the native code.  

What Java runtime are you using? 
Does that happen every time you run the program?
Do the attached jar files produce the same results? If not, let me know which 
one fails.

Original comment by alex%1st...@gtempaccount.com on 2 Jul 2012 at 6:12

Attachments:

GoogleCodeExporter commented 8 years ago
Hi,

I'm using java version: 1.6.0_24-b07
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)

The bug happens every time.

The bug happens with the demo code provided in the
jar: org.jnativehook.example.NativeHookDemo

I can reproduce by running the following from the command line:
java -jar JNativeHook.jar

The attachments you sent didn't come through, perhaps Gmail stripped them
off.

I think you're right about the way the thread is getting shut down, I made
the following edits to NativeHookDemo and it seems to have solved the
problem.

In the NativeHookDemo constructor I added:
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

public void windowClosed(WindowEvent e) {
    -- snip --

    // Remove these 2 lines
    // System.runFinalization();
    // System.exit(0);
}

In Main, I believe it is now
recommended<http://bitguru.wordpress.com/2007/03/21/will-the-real-swing-single-t
hreading-rule-please-stand-up/>that
Swing components are created in the AWT event thread.

public static void main(String[] args) {

    SwingUtilities.invokeLater(new Runnable()
    {
        public void run() {
            new NativeHookDemo();
        }
    });
 }

Andrew

Original comment by awbra...@gmail.com on 2 Jul 2012 at 1:58

GoogleCodeExporter commented 8 years ago
The jar files are attached to the bug report on google code.

Original comment by alex%1st...@gtempaccount.com on 2 Jul 2012 at 4:40

GoogleCodeExporter commented 8 years ago
Both  JNativeHook_Test1.jar and  JNativeHook_Test2.jar run without
exception.

Andrew

Original comment by awbra...@gmail.com on 2 Jul 2012 at 5:51

GoogleCodeExporter commented 8 years ago
Should be fixed in revision 557

Original comment by alex%1st...@gtempaccount.com on 2 Jul 2012 at 6:56