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 32873 - failure in MenuBar$LazyMenu
Summary: failure in MenuBar$LazyMenu
Status: VERIFIED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 3.x
Hardware: PC Windows ME/2000
: P1 blocker (vote)
Assignee: Petr Nejedly
URL:
Keywords: THREAD
Depends on:
Blocks:
 
Reported: 2003-04-14 17:26 UTC by usommerw
Modified: 2008-12-22 17:54 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Proper threading (1.71 KB, patch)
2003-04-15 07:35 UTC, Petr Nejedly
Details | Diff
Binary patch for openide against release35 (8.66 KB, application/octet-stream)
2003-04-22 13:16 UTC, Petr Nejedly
Details

Note You need to log in before you can comment on or make changes to this bug.
Description usommerw 2003-04-14 17:26:56 UTC
I use a the platform (trunk) build from about 02/11/2003, 
which had a focus problem with top components!!!! I hope, 
you will be able to reproduce the problem with the current 
platform build.

I use lazy creation of menu and toolbars at runtime by the 
following methods:
host = ModuleLayeredFileSystem.getUserModuleLayer();
            Collection urls = new ArrayList();
            urls.add(new URL(<tmp_file_name>));
            synchronized (host){
                host.addURLs(urls);
            }

and for removing I call analogously:
            synchronized (host){
                  host.removeURLs(urls);
            }

In generally it works well, but we got sometimes 
exceptions of the type below, in case there are 
overlapping definitions for menus in a short
sequence of calls removeURLs() and addURLs().

Annotation: Exception occurred in Request
Processorjava.lang.ArrayIndexOutOfBoundsException: No such 
child: 3
at java.awt.Container.getComponent(Container.java:237)
at javax.swing.JMenuBar.getComponentAtIndex
(JMenuBar.java:233)
at javax.swing.JMenuBar.getMenu(JMenuBar.java:188)
at
javax.swing.plaf.basic.BasicMenuBarUI$ChangeHandler.stateCh
anged(BasicMenuBarUI.java:179)
at
javax.swing.DefaultButtonModel.fireStateChanged
(DefaultButtonModel.java:361)
at javax.swing.DefaultButtonModel.setMnemonic
(DefaultButtonModel.java:295)
at javax.swing.AbstractButton.setMnemonic
(AbstractButton.java:1370)
at javax.swing.AbstractButton.setMnemonic
(AbstractButton.java:1391)
at org.openide.awt.Actions.setMenuText(Actions.java:165)
at org.openide.awt.MenuBar$LazyMenu.updateProps
(MenuBar.java:287)
at org.openide.awt.MenuBar$LazyMenu.propertyChange
(MenuBar.java:299)
at
org.openide.util.WeakListener$PropertyChange.propertyChange
(WeakListener.jav
a:485)
at org.openide.nodes.Node.fireOwnPropertyChange
(Node.java:937)
at org.openide.nodes.Node.fireDisplayNameChange
(Node.java:797)
at org.openide.loaders.DataNode.fireChangeAccess
(DataNode.java:484)
at org.openide.loaders.DataNode$PropL.run
(DataNode.java:635)
at org.openide.util.Task.run(Task.java:136)
at
org.openide.util.RequestProcessor$Task.run
(RequestProcessor.java:328)[catch]
at
org.openide.util.RequestProcessor$Processor.run
(RequestProcessor.java:667)

Jesse Glick guided to be the following is wrong:
MenuBar.LazyMenu is at fault for not using 
SwingUtilities.invokeLater. 

I used (to reproduce to failure) the following two files.
Please, play with the following sequence:
add(file1), remove(file1), add(file2), remove(file2), ...

file1:
<?xml version="1.0"?>
<filesystem>
  <folder name="Menu">
    <folder name="File">
      <file name="org-openide-actions-
CloseViewAction.instance"/>
      <file name="org-openide-actions-
SaveAction.instance"/>
      <attr boolvalue="true" name="org-openide-actions-
CloseViewAction.instance/org-openide-actions-
SaveAction.instance"/>
      <file name="SeparatorRo12.instance">
        <attr name="instanceClass" 
stringvalue="javax.swing.JSeparator"/>
      </file>
      <attr boolvalue="true" name="org-openide-actions-
SaveAction.instance/SeparatorRo12.instance"/>
      <file name="org-openide-actions-
CopyAction.instance"/>
      <attr boolvalue="true" 
name="SeparatorRo12.instance/org-openide-actions-
CopyAction.instance"/>
      <file name="org-openide-actions-
EditAction.instance"/>
      <attr boolvalue="true" name="org-openide-actions-
CopyAction.instance/org-openide-actions-
EditAction.instance"/>
    </folder>
    <folder name="Edit"/>
    <folder name="View">
      <file name="org-netbeans-core-actions-
GlobalPropertiesAction.instance"/>
      <file name="SeparatorRo14.instance">
        <attr name="instanceClass" 
stringvalue="javax.swing.JSeparator"/>
      </file>
      <attr boolvalue="true" name="org-openide-actions-
GlobalPropertiesAction.instance/SeparatorRo14.instance"/>
      <file name="org-netbeans-core-actions-
MoveDownAction.instance"/>
      <attr boolvalue="true" 
name="SeparatorRo14.instance.instance/org-openide-actions-
MoveDownAction.instance"/>
      <file name="org-netbeans-core-actions-
MoveUpAction.instance"/>
      <attr boolvalue="true" 
name="MoveDownAction.instance.instance/org-openide-actions-
MoveUpAction.instance"/>
      <file name="org-netbeans-core-actions-
NextTabAction.instance"/>
      <attr boolvalue="true" 
name="MoveUpAction.instance.instance/org-openide-actions-
NextTabAction.instance"/>
      <file name="org-netbeans-core-actions-
UndoAction.instance"/>
      <attr boolvalue="true" 
name="NextTabAction.instance.instance/org-openide-actions-
UndoActionAction.instance"/>
      <file name="org-netbeans-core-actions-
UndockAction.instance"/>
      <attr boolvalue="true" 
name="UndoActionAction.instance.instance/org-openide-
actions-UndockAction.instance"/>
      <file name="org-netbeans-core-actions-
ViewAction.instance"/>
      <attr boolvalue="true" 
name="UndockAction.instance.instance/org-openide-actions-
ViewAction.instance"/>
    </folder>
    <folder name="Execute">
      <file name="org-openide-actions-
OpenLocalExplorerAction.instance"/>
    </folder>
    <folder name="Tools">
      <file name="org-openide-actions-
ReorderAction.instance"/>
      <file name="SeparatorRo19.instance">
        <attr name="instanceClass" 
stringvalue="javax.swing.JSeparator"/>
      </file>
      <attr boolvalue="true" name="org-openide-actions-
ReorderAction.instance/SeparatorRo19.instance"/>
      <file name="org-openide-actions-
ToolsAction.instance"/>
      <attr boolvalue="true" 
name="SeparatorRo19.instance/org-openide-actions-
ToolsAction.instance.instance"/>
    </folder>
    <attr name="OpenIDE-Folder-Order" 
stringvalue="File/Edit/View/Execute/Tools"/>
  </folder>
  <folder name="Shortcuts">
    <file name="C-S.instance">
      <attr name="instanceClass" 
stringvalue="org.openide.actions.SaveAction"/>
    </file>
    <file name="C-1.instance">
      <attr name="instanceClass" 
stringvalue="org.netbeans.core.actions.GlobalPropertiesActi
on"/>
    </file>
  </folder>
  <folder name="Actions">
    <folder name="Rochade">
      <file name="org-openide-actions-
CloseViewAction.instance"/>
      <file name="org-openide-actions-
SaveAction.instance"/>
      <file name="org-openide-actions-
CopyAction.instance"/>
      <file name="org-openide-actions-
CloseViewAction.instance"/>
      <file name="org-openide-actions-
EditAction.instance"/>
      <file name="org-netbeans-core-actions-
GlobalPropertiesAction.instance"/>
    </folder>
  </folder>
</filesystem>


file2:
<?xml version="1.0"?>
<filesystem>
  <folder name="Menu">
    <folder name="File"/>
    <folder name="Edit"/>
    <folder name="View">
      <file name="org-netbeans-core-actions-
GlobalPropertiesAction.instance"/>
    </folder>
    <folder name="Execute">
      <file name="org-openide-actions-
ReorderAction.instance"/>
    </folder>
    <folder name="Tools"/>
    <attr name="OpenIDE-Folder-Order" 
stringvalue="File/Edit/View/Execute/Tools"/>
  </folder>
  <folder name="Shortcuts">
    <file name="C-1.instance">
      <attr name="instanceClass" 
stringvalue="org.netbeans.core.actions.GlobalPropertiesActi
on"/>
    </file>
    <file name="C-I.instance">
      <attr name="instanceClass" 
stringvalue="de.rochade.rap.applications.ap.actions.Connect
ionManagerAction"/>
    </file>
  </folder>
  <folder name="Actions">
    <folder name="Rochade">
      <file name="org-openide-actions-
ReorderAction.instance"/>
      <file name="org-netbeans-core-actions-
GlobalPropertiesAction.instance"/>
    </folder>
  </folder>
</filesystem>
Comment 1 Vitezslav Stejskal 2003-04-14 19:26:10 UTC
I am not sure why this was assigned to projects, but I guess the
problem is somewhere in core/openide.
Comment 2 Petr Nejedly 2003-04-15 07:31:59 UTC
OK, I'm on it.
Comment 3 Petr Nejedly 2003-04-15 07:35:24 UTC
Created attachment 9942 [details]
Proper threading
Comment 4 Petr Nejedly 2003-04-15 07:36:33 UTC
I've fixed it in trunk using the attached patch.
You can easily backport it to older release (3.4.1) if you need so.
Comment 5 Petr Nejedly 2003-04-15 07:40:48 UTC
Please verify it works for you.
Comment 6 usommerw 2003-04-15 11:24:10 UTC
Thank you very much for the fast fix.
It works well for us!!!!
The dynamic handling of menus is really a basic and 
critical feature of our platform based application.
Comment 7 Petr Nejedly 2003-04-22 13:16:52 UTC
Created attachment 10062 [details]
Binary patch for openide against release35
Comment 8 Petr Nejedly 2003-04-22 13:18:20 UTC
Dafe, could you please review the attached source patch?
Comment 9 _ ttran 2003-04-22 13:57:19 UTC
approved for 3.5
Comment 10 David Simonek 2003-04-22 15:27:19 UTC
Yes, fix is replan of updateProps() call into Event dispatch thread if
needed. Correctly implemented IMO. Reviewed.
Comment 11 Petr Nejedly 2003-04-22 15:29:12 UTC
Backported to release35

Checking in MenuBar.java;
/cvs/openide/src/org/openide/awt/Attic/MenuBar.java,v  <-- 
MenuBar.java
new revision: 1.49.8.2; previous revision: 1.49.8.1