JDK-4667544 : CSH Locks Application When Using Other Than Default Event Queue
  • Type: Bug
  • Status: Resolved
  • Resolution: Fixed
  • Component: client-libs
  • Sub-Component: java.awt
  • Priority: P4
  • Affected Version: 1.4.0,1.4.1
  • OS: windows_2000
  • CPU: x86
  • Submit Date: 2002-04-12
  • Updated Date: 2003-07-21
  • Resolved Date: 2002-09-06
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 Availabitlity Release.

To download the current JDK release, click here.
Other
1.4.2 mantisResolved
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description

Name: rl43681			Date: 04/12/2002


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

FULL OPERATING SYSTEM VERSION : Microsoft Windows 2000
[Version 5.000.2195]


ADDITIONAL OPERATING SYSTEMS : Mandrake Linux 8.0, Solaris
2.8



A DESCRIPTION OF THE PROBLEM :
Subclassing java.awt.EventQueue is handy for logging and
automating the busy cursor.  If you use replace the event
queue with another and invoke context-sensitive help, the
program locks up every time.  I can only speak for what
I've seen in my Swing applications, but context-sensitive
help appears to be the only part that is adversely affected
by replacing the event queue.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Replace the system event queue.  For example, put the
following line at the beginning of main():

  Toolkit.getDefaultToolkit().getSystemEventQueue().push(
    new java.awt.EventQueue() );

In reality, you'd probably push a subclass EventQueue.  But
this demonstrates the problem.

2. Invoke context-sensitive help.
3. Try to click on anything in the application.

EXPECTED VERSUS ACTUAL BEHAVIOR :
I expected the help window to appear and the cursor to
revert back to its original shape.  What happened is the
cursor changed shape as expected (i.e., to the pointer with
the question mark), but subsequent clicks were ignored.
Not only did the help window not come up, the cursor never
reverted back to normal and the application had to be
killed.

This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.help.*;
import javax.swing.*;

//==============================================================================
// NOTE: For the code to bring up help, you'll need to comment out the event
//       queue portion of main() and create a simple HelpSet called "HelpSet"
//       that has a single target called "textarea".
//==============================================================================

public class HelpDemo extends JFrame {

    private HelpBroker helpBroker; // Manages access to help


    public HelpDemo() {

        addWindowListener( new WindowAdapter() {
            public void windowClosing( WindowEvent e ) {
                System.exit( 0 );
            }
        } );

        initHelpSystem();

        // Create the menu bar.
        JMenuBar menuBar = new JMenuBar();
        setJMenuBar( menuBar );

        // Build the Help menu.
        JMenu menu = new JMenu( "Help" );
        menu.setMnemonic( KeyEvent.VK_H );
        menuBar.add( menu );

        JMenuItem item = new JMenuItem( "Contextual Help" );
        item.setMnemonic( KeyEvent.VK_H );
        item.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_F1,ActionEvent.SHIFT_MASK) );
        item.addActionListener(
            new CSH.DisplayHelpAfterTracking(helpBroker) );
        menu.add( item );

        // Add a scrollable area to the window.
        JTextArea textArea = new JTextArea( 5, 30 );
        CSH.setHelpIDString( textArea, "textarea" );
        textArea.setEditable( false );
        textArea.setText( "Click here after invoking context-sensitive help!" );
        JScrollPane scrollPane = new JScrollPane( textArea );
        getContentPane().add( scrollPane, BorderLayout.CENTER );
    }

    /**
     * This method attempts to load the application help.
     */

    private void initHelpSystem() {

        try {
            ClassLoader loader = HelpDemo.class.getClassLoader();
            URL url = HelpSet.findHelpSet( loader, "HelpSet" );

            if ( url == null ) {
                System.err.println( "Can't locate help set!" );
                System.exit( 1 );
            }

            HelpSet helpSet = new HelpSet( loader, url );
            helpBroker = helpSet.createHelpBroker();
            helpBroker.enableHelpKey( getRootPane(), "demo.top", helpSet );

        } catch ( Exception e ) {
            System.err.println( "initHelpSystem(): " + e );
            System.exit( 1 );
        }
    }


    public static void main( String[] args ) {

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// <<<foobar>>> COMMENT THIS OUT TO MAKE CONTEXT-SENSITIVE HELP WORK
        Toolkit.getDefaultToolkit().getSystemEventQueue().push(
            new EventQueue() );
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

        HelpDemo window = new HelpDemo();

        window.setTitle( "Help Demo" );
        window.setSize( 450, 260 );
        window.setVisible( true );
    }
}

---------- END SOURCE ----------
(Review ID: 144983) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis FIXED IN: mantis INTEGRATED IN: mantis
2004-06-14

EVALUATION The problem is that the CSH tracking code needs to process the events from the current event queue. Unfortunately when the customer sets the SystemEventQueue to some new queue with call Toolkit.getDefaultToolkit().getSystemEventQueue().push(new EventQueue()); subsequents calls to Toolkit.getDefaultToolkit().getSystemEventQueue() returns the original event queue not the updated queue. This causes JavaHelp CSH to hang because it's looking to process events from the SystemEventQueue but cannot. I'm passing this on the AWT team to resolve as this appears to be there problem in not returning the pushed EventQueue. ###@###.### 2002-04-16 Commit to fix in mantis (hang). ###@###.### 2002-04-18 Name: ssR10077 Date: 05/18/2002 ====================================================================== Name: ssR10077 Date: 08/20/2002 The problem is Toolkit.getSystemEventQueue() returns the queue created with Toolkit even after other queues are pushed over it using EventQueue.push(...). The idea of the fix is to replace the EVENT_QUEUE_KEY value in AppContext to the topmost queue in the stack. ======================================================================
2004-06-11

SUGGESTED FIX ------- EventQueue.java ------- *** /tmp/dqOaGHd Wed Aug 14 18:23:38 2002 --- EventQueue.java Wed Aug 14 18:22:21 2002 *************** *** 28,33 **** --- 28,34 ---- import sun.awt.SunToolkit; import sun.awt.DebugHelper; import sun.awt.AWTAutoShutdown; + import sun.awt.AppContext; /** * <code>EventQueue</code> is a platform-independent class *************** *** 565,570 **** --- 566,576 ---- } nextQueue = newEventQueue; + + AppContext appContext = AppContext.getAppContext(); + if (appContext.get(AppContext.EVENT_QUEUE_KEY) == this) { + appContext.put(AppContext.EVENT_QUEUE_KEY, newEventQueue); + } } /** *************** *** 610,615 **** --- 616,626 ---- } } } + AppContext appContext = AppContext.getAppContext(); + if (appContext.get(AppContext.EVENT_QUEUE_KEY) == this) { + appContext.put(AppContext.EVENT_QUEUE_KEY, previousQueue); + } + previousQueue = null; } }
2004-06-11