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 26619 - NPE when using Actions.SubMenuModel according to old template
Summary: NPE when using Actions.SubMenuModel according to old template
Status: VERIFIED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Window System (show other bugs)
Version: 3.x
Hardware: PC Linux
: P2 blocker (vote)
Assignee: Petr Nejedly
URL: http://openide.netbeans.org/servlets/...
Keywords:
Depends on: 21197
Blocks: 26689
  Show dependency tree
 
Reported: 2002-08-19 17:41 UTC by Jesse Glick
Modified: 2008-12-22 23:49 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2002-08-19 17:41:57 UTC
P2 because it is a regression that can cause
exceptions to be thrown by module code which
worked before.

I think rev. 1.60 of Actions.java caused a problem:

---%<---
revision 1.60
date: 2002/05/14 10:15:53;  author: pnejedly; 
state: Exp;  lines: +20 -11
Fix for #21197. Not optimal because it assumes the
multi-action will perform the first subaction on
accelerator stroke.
---%<---
[...other stuff then:]
+        boolean useAccel() {
+            return subModel.getCount() <= 1;
+        }
---%<---

The following stack trace seems to be triggered by it:

---%<---
java.lang.NullPointerException
 at
wfedit.actions.WFLocalAction$ActSubMenuModel.getCount(WFLocalAction.java:106
)
 at
org.openide.awt.Actions$SubMenu.useAccel(Actions.java:1021)
 at
org.openide.awt.Actions.updateKey(Actions.java:744)
 at
org.openide.awt.Actions$MenuBridge.updateState(Actions.java:512)
 at
org.openide.awt.Actions$SubMenu.<init>(Actions.java:949)
 at
wfedit.actions.WFLocalAction$SpecialSubMenu.<init>(WFLocalAction.java:83)
 at
wfedit.actions.WFLocalAction.getMenuPresenter(WFLocalAction.java:58)
 at
org.openide.awt.MenuBar$LazyMenu$MenuFolder.createInstance(MenuBar.java:403)
---%<---

from a submenu action created according to the
standard template, i.e.:

---%<---
// ...
private static final class SpecialSubMenu extends
Actions.SubMenu {
    // ...
    public void addNotify() {
        model.addNotify();
        super.addNotify();
    }
}
private static final class ActSubMenuModel implements
Actions.SubMenuModel {
    private List displayNames; // List<String>
    private List associatedInfo; // List<Object>
    public int getCount() {
        return displayNames.size();
    }
    // ...
}
---%<---

I have this seen same problem as well.

The regression appears to be this: that useAccel()
should not be called until addNotify() has been
called on the submenu. Otherwise it is too early
to know whether it should use an accelerator or
not, since that depends on information from the
model, which should not be computed until the menu
is really displayed.

Workaround: replace

    public int getCount() {
        return displayNames.size();
    }

with

    public int getCount() {
        return displayNames != null ?
displayNames.size() : 0;
    }

I could update the apisupport template to use this
workaround, but it would be nicer to just get the
bug fixed so there is no regression.
Comment 1 Petr Nejedly 2002-08-21 11:23:11 UTC
addNotify, as proven over the time, is generally quite bad place for
lazy initialization but the Swing gives us no better alternative.
I had to split the initialization and place only part of it
to the addNotify to fulfill this request while keeping Swing happy
(I had layout problems otherwise)
Comment 2 _ mihmax 2002-11-24 15:30:42 UTC
Hi Petr and Jesse 
(not sure who did the commit),

where're the .diff-s ?!!!

I'd like to get this bug fixed in 3.4.1, but how can I apply a nothing
to the code ;-) 

Sincerely yours,
Maxym Mykhalchuk,
Netbeans 3.4.1 "Merak" Release Coordinator
Comment 3 Jesse Glick 2002-11-29 16:23:40 UTC
Petr, is a diff available for this fix? I have no idea how you fixed
it or when.
Comment 4 Jesse Glick 2002-12-02 19:00:42 UTC
BTW it is easy to reproduce in current 3.4.1 builds:

- download apisupport-2.10.2.nbm from apisupport.netbeans.org

- install

- open Tools menu

- NPE thrown many times
Comment 5 Jaroslav Tulach 2002-12-03 09:55:01 UTC
Hi. This issue is marked as 3.4.1_CANDIDATE. It means that it should be
integrated into release341 one branch. The plan at
http://www.netbeans.org/devhome/docs/releases/34/index.html expected beta1 to be
produced on Dec01. That did not happen due to a lot of outstanding not
integrated candidates like this one. 

Would it be possible to spend few minutes by backporting this fix? Thank you in
advance.
Comment 6 Jesse Glick 2002-12-03 22:17:34 UTC
Petr is on vacation, I guess, and no one seems to know where the diff is.
Comment 7 _ mihmax 2002-12-06 14:28:05 UTC
OK, this won't go into 3.4.1 :-(
What a shame, Petr ;-)
Comment 8 Marian Mirilovic 2004-03-15 14:57:56 UTC
fixed long time ago.....
...verified....
if it happens again reopen please