This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 35953 - IllegalStateException permanently appears in log
Summary: IllegalStateException permanently appears in log
Status: VERIFIED FIXED
Alias: None
Product: utilities
Classification: Unclassified
Component: Search (show other bugs)
Version: 3.x
Hardware: PC Windows ME/2000
: P2 blocker (vote)
Assignee: Marian Petras
URL:
Keywords: THREAD
: 35955 35973 36178 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-09-08 10:31 UTC by Jiri Skrivanek
Modified: 2005-04-04 13:22 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Full stack trace (1.21 KB, text/plain)
2003-09-08 10:31 UTC, Jiri Skrivanek
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jiri Skrivanek 2003-09-08 10:31:01 UTC
The following exception is continuously appearing
in ide.log if you click on a node, for example in
the explorer.

java.lang.IllegalStateException: This must happen
in the event thread!
	at
org.openide.awt.Actions$Bridge.propertyChange(Actions.java:272)

Tested in build 20030908-0621, JDK1.4.1_03, WindowsXP.
Comment 1 Jiri Skrivanek 2003-09-08 10:31:55 UTC
Created attachment 11541 [details]
Full stack trace
Comment 2 pzajac 2003-09-08 13:39:37 UTC
reassigned to openide/actions
Comment 3 Marian Mirilovic 2003-09-08 14:02:48 UTC
*** Issue 35955 has been marked as a duplicate of this issue. ***
Comment 4 Jiri Skrivanek 2003-09-16 07:08:50 UTC
Exception comes from module org.netbeans.modules.search. That's why I
am cc-ing issues@utilities.netbeans.org.
Comment 5 dmladek 2003-09-17 10:02:31 UTC
Still happening in NBdev #200309170100
Comment 6 Marian Petras 2003-09-17 16:15:14 UTC
*** Issue 35973 has been marked as a duplicate of this issue. ***
Comment 7 Marian Petras 2003-09-17 16:23:44 UTC
It is caused by calling

    findAction.setActionPerformer(...)

in a request processor's thread in method

    org.netbeans.modules.search.FindActionManager.propertyChange(...)

It was being called directly in the original source code and moved to
a request processor later in order to avoid a deadlock. I do know the
details of the deadlock so I will try to change it back (so the method
is called in the default thread) and see if the change causes some
deadlock or not. (The above change was made more than three years ago.)
Comment 8 Marian Petras 2003-09-18 07:33:54 UTC
*** Issue 36178 has been marked as a duplicate of this issue. ***
Comment 9 dmladek 2003-09-18 08:43:14 UTC
:-O Change was made 3 years ago and now, 2 weeks ago started throwing
an E.? Incredible:-|
Comment 10 Marian Petras 2003-09-18 09:03:18 UTC
That's not so incredible. The exception started being thrown simply
because a test whether the method (mentioned in the initial bug
description) is called in the AWT Event thread was added. The test was
added to revision 1.87 of source code of class org.openide.awt.Actions.
Comment 11 Jesse Glick 2003-09-18 14:02:34 UTC
Why close issue #36178? I already have a patch for it and was planning
to check it in shortly. If interested, try:

         if(TopComponent.Registry.PROP_CURRENT_NODES.equals(propName)  ||
            TopComponent.Registry.PROP_ACTIVATED.equals(propName)) {
-            // PREVENT deadlock
-            // do not depend on locking order of
-            // CookieSet[.add/remove()] and TopComponent[.attach()].
-            RequestProcessor.getDefault().post(new Runnable() {
-                public void run() {
-                    someoneActivated();
-                }
-            });
+               someoneActivated();
         }
     }

Sorry that I didn't check it in already - I was afraid of recreating
whatever deadlock was being mentioned here. (Maybe it is obsolete.) I
am running with this patch for a while now with no apparent problems.
Comment 12 Marian Petras 2003-09-18 15:38:23 UTC
Jesse, it is clearly THE FIX. I've tried it, too, and found only a
minor problem so far. The minor problem is that the exception is still
thrown if you try to uninstall the Utilities module individually. It
is because the module installer's method uninstalled() is apparently
not called in the AWT event queue.
Comment 13 Jesse Glick 2003-09-18 17:05:29 UTC
OK, so change unhook slightly:

public void unhook() {
    setHookListener(null);
    performer = null;
    Mutex.EVENT.readAccess(new Runnable() {
        public void run() {
            someoneActivated();
        }
    });
    findAction = null;
}

That should be all you need. someoneActivated() uses GUI methods (like
the window system) and ought to be called from EQ.
Comment 14 Marian Petras 2003-09-19 16:42:16 UTC
I just integrated the fix.

Diff of method propertyChange(...):

-            // PREVENT deadlock
-            // do not depend on locking order of
-            // CookieSet[.add/remove()] and TopComponent[.attach()].
-            RequestProcessor.getDefault().post(new Runnable() {
-                public void run() {
-                    someoneActivated();
-                }
-            });
+                someoneActivated();

(i.e. exactly as Jesse suggested)

Diff of method unhook():

-        someoneActivated();
+        
+        /*
+         * We just need to run method 'someoneActivated'
+         * in the AWT event dispatching thread. We use
+         * Mutex.EVENT for this task.
+         * 
+         * We use Mutex.Action rather than Runnable.
+         * The reason is that Runnable could be run
+         * asynchronously which is undesirable during
+         * uninstallation (we do not want any instance/class
+         * from this module to be in use by the time
+         * ModuleInstall.uninstalled() returns).
+         */
+        Mutex.EVENT.readAccess(new Mutex.Action() {
+            public Object run() {
+                someoneActivated();
+                return null;
+            }
+        });


Comment 15 Jesse Glick 2003-09-20 04:54:30 UTC
All right... careful with blocking on EQ from ModuleInstall, though. 
Not really safe. Of course it is also undesirable for module code to 
run after a module has nominally been uninstalled (as frequently 
happens in the current system). I am not sure what the best 
resolution for this conflict is currently; using Mutex.Action here 
for now ought to be OK.
Comment 16 Jaroslav Tulach 2003-09-20 16:36:30 UTC
The best resolution would be to rewrite the code to new ActionMap
system: instead of listening on each change of activated window,
listen on creation of new ones. If a new TopComponent is created and
it is of desired type, call topComponent.getActionMap().put
("org.openide.actions.FindAction", yourAction) where yourAction is
your current performer, but implements javax.swing.Action. Done this
way, threading should no longer be problem for switching.
Comment 17 Jiri Skrivanek 2003-09-22 07:44:25 UTC
Verified in build 200309220100.
Comment 18 Jesse Glick 2003-09-23 17:14:23 UTC
Is there a way to listen to creation of new TopComponent's? If so,
then of course that is the preferred technique.

Ideally, I guess, the ActionMap of a TopComponent would be composed
from some layer context, so that search module could register e.g.

"TopComponentActions/org.openide.explorer.ExplorerPanel": "C-F" ->
instance of SearchAction

Then no listener would be needed; the TC would look for appropriate
bindings when it was created.
Comment 19 Marian Petras 2005-04-04 13:22:53 UTC
FYI: The code was rewritten to the new ActionMap system (as suggested by
jtulach) as a part of fix of bug #56993.