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 143060 - Startup regression: org.netbeans.modules.db.sql.editor.ui.actions.SQLHistoryAction
Summary: Startup regression: org.netbeans.modules.db.sql.editor.ui.actions.SQLHistoryA...
Status: RESOLVED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: SQL Editor (show other bugs)
Version: 6.x
Hardware: All All
: P4 blocker (vote)
Assignee: Jiri Rechtacek
URL: http://wiki.netbeans.org/FitnessViaWh...
Keywords: PERFORMANCE, REGRESSION, TEST
Depends on: 133009 152576
Blocks:
  Show dependency tree
 
Reported: 2008-08-06 14:26 UTC by Alexander Kouznetsov
Modified: 2009-08-07 16:48 UTC (History)
5 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Stacktrace (1.80 KB, text/plain)
2008-08-06 14:27 UTC, Alexander Kouznetsov
Details
Stacktrace (1.80 KB, text/plain)
2008-08-19 12:32 UTC, Alexander Kouznetsov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Kouznetsov 2008-08-06 14:26:47 UTC
Performance test reports there is a NetBeans startup regression which is caused by the loading of the following class:

org.netbeans.modules.db.sql.editor.ui.actions.SQLHistoryAction

Please don't load this class during NetBeans startup.

Comment from jtulach: "Possibly bug. Wrap by alwaysEnabledAction, I guess."
Comment 1 Alexander Kouznetsov 2008-08-06 14:27:46 UTC
Created attachment 66700 [details]
Stacktrace
Comment 2 Andrei Badea 2008-08-06 22:25:03 UTC
SQL history issue.
Comment 3 John Baker 2008-08-07 00:32:14 UTC
enabled is overridden
Comment 4 John Baker 2008-08-11 19:56:10 UTC
removed enable()

10577167a600
Comment 5 Quality Engineering 2008-08-12 04:13:27 UTC
Integrated into 'main-golden', available in build *200808120201* on http://bits.netbeans.org/dev/nightly/
Changeset: http://hg.netbeans.org/main/rev/10577167a600
User: John Baker <jbaker@netbeans.org>
Log: #143060 Startup regression: org.netbeans.modules.db.sql.editor.ui.actions.SQLHistoryAction
Comment 6 Roman Mostyka 2008-08-12 10:19:48 UTC
mrkam, please verify that this issue is really fixed.
Comment 7 Alexander Kouznetsov 2008-08-19 12:32:04 UTC
According to 080819 Dev build test results this class is still being loaded.
Comment 8 Alexander Kouznetsov 2008-08-19 12:32:34 UTC
Created attachment 67796 [details]
Stacktrace
Comment 9 John Baker 2008-08-19 18:02:08 UTC
SQLHistoryAction is no longer enabled so I don't see how it could be loaded at startup.

Are you sure you used the Aug 19 build ?
Comment 10 John Baker 2008-08-19 18:05:00 UTC
Why is the latest attachment named mysql2.txt ?
Comment 11 Alexander Kouznetsov 2008-08-19 18:24:20 UTC
Yes, this is fresh build of trunk I made today, the name of the attachment is quite random, please don't pay attention
to the name of this file.

If you would like to reproduce test results, edit ide.kit/build.xml to add the following line: 
    <property name="test.run.args" value="-ea -XX:PermSize=32m -XX:MaxPermSize=200m -Xmx256m -Xverify:none"/>
open ide.kit project in IDE and invoke Run File over WhitelistTest in functional test packages.
Comment 12 Andrei Badea 2008-08-21 18:12:07 UTC
Regression? Not sure how a loading class with no instance fields can have a significant performance overhead and be
considered a regression. The complex registration of Actions.alwaysEnabled() does not pay off IMHO. Sorry.

Comment 13 Jaroslav Tulach 2008-08-22 10:56:02 UTC
I have to reopen this bug, as the resolution seems to be one of "my feature is the most important one in the IDE and I 
want to feed it to every user of NetBeans regardless of the fact that they do not touch SQL at all" attitude. I am 
sorry, but performance team has to fight with this attitude widely spread among our development team.

If you are still not convinced, the performance team is ready to have a teaching session when we can explain you and 
your team why fighting with "my feature is the most important one" attitude is essential to success of NetBeans in 
supporting enormous range of less and less related technologies.
Comment 14 Andrei Badea 2008-08-22 12:04:39 UTC
> my feature is the most important one in the IDE and I want to feed it
> to every user of NetBeans regardless of the fact that they do not touch SQL at all

Irrelevant. Let's keep this discussion technical. Please provide data proving that instantiating SQLHistoryAction slows
down startup. 

Also, please explain the stack trace in desc9. I don't see a trace of the SQL editor there, just core loading
SQLHistoryAction. Please make core not load the action, or load it lazily instead.
Comment 15 Andrei Badea 2008-08-22 12:08:36 UTC
Another thing: SQLHistoryAction is registered in the toolbar of the SQL editor, just other action, such as RunSQLAction.
Both these actions have shortcuts. How come you care about SQLHistoryAction, but not RunSQLAction?
Comment 16 Jaroslav Tulach 2008-08-22 14:29:47 UTC
1. Obviously it occupies permanent memory.
2. Fix both actions if you are able.

> Let's keep this discussion technical.

I would love to, so please stop playing games with reassigning, stop looking for reasons why you do not want to help 
us improve the IDE and try a least a bit to fix the issue. It is not hard, if you find at least a bit of will.
Comment 17 Andrei Badea 2008-08-22 15:21:34 UTC
Again:

> Also, please explain the stack trace in desc9. I don't see a trace of the SQL editor there, 
> just core loading SQLHistoryAction. Please make core not load the action, or load it lazily instead.

Somewhere above you say "feed it [...] regardless of the fact that they do not touch SQL". Well, the SQL editor doesn't
do anything apart from giving the action a shortcut. I don't know why that should cause the action to be initialized.
Please consider not loading the action until you actually need it. If that is not possible, then please consider
accepting the burden that it has on the permgen. I believe the burden is not high (correct me with numbers), and that
actions are such a basic IDE concept (connected to shortcuts, etc.), that they can be loaded at startup if necessary.
Comment 18 John Baker 2008-08-22 16:22:45 UTC
Is there any more documentation than the API docs to fix this ?
Comment 19 Jaroslav Tulach 2008-08-22 16:36:16 UTC
> Well, the SQL editor doesn't do anything apart from giving the action a shortcut. 
> I don't know why that should cause the action to be initialized.

I tried! There is a patch in issue 133009 which basically does this:
http://www.netbeans.org/nonav/issues/showattachment.cgi/67930/X.diff
but it does not work. Looks like the only way to go is to use the declarative actions like alwaysEnabled more.

Re: documentation. We have 
http://bits.netbeans.org/dev/javadoc/org-openide-awt/org/openide/awt/Actions.html#alwaysEnabled(java.awt.event.ActionListener, 
java.lang.String, java.lang.String, boolean) or you can use the actions wizard in apisupport.
Comment 20 John Baker 2008-08-22 16:51:01 UTC
I think that this issue should be waived for 6.5 until Actions can be loaded without using enabledAction

It still doesn't make sense to me that some actions are not whitelisted when they don't use enabledAction.
Comment 21 Andrei Badea 2008-08-22 16:58:25 UTC
Good to know. Suggest postponing this issue until issue 133009 is resolved. However, even in case issue 133009 is not
fixed I do not see it a big problem if the actions which have a shortcut are loaded. I simply do not believe that 2% of
startup time (5% before LazyAction, 3% with it) make a big difference.

I also realized that alwaysEnabled() would require me to duplicate the display name bundle label and the icon path in
both layer.xml and the class. This breaks the DRY principle

http://en.wikipedia.org/wiki/Don%27t_repeat_yourself

and I see it as another reason to avoid alwaysEnabled(). It also requires a factory method! Too much complexity, too
little gain.
Comment 22 Alexander Kouznetsov 2008-08-25 17:39:59 UTC
Is there still any missing information? If not, I would remove INCOMPLETE keyword.
Comment 23 John Baker 2008-08-26 06:17:29 UTC
If there's agreement to postpone this until issue 133009 is resolved then I presume this class needs to be added to the
blacklist ?
Comment 24 Jaroslav Tulach 2008-08-28 07:48:32 UTC
Fix the action registration for 6.5 by using Actions.alwaysEnabled, please. Issue 133009 is unrelated. My reference to 
it just explains why shortcut needs to be initialized on start. Use Actions.alwaysEnabled as much as you can. If you 
need help writing the registration, please use the Action wizard in apisupport from NetBeans 6.5 and generate new 
action.
Comment 25 John Baker 2008-08-29 07:34:54 UTC
> please use the Action wizard in apisupport from NetBeans 6.5 and generate new action.

The Action wizard can't be used for the SQL Editor.  There is no "Global toolbar"   
And I have no idea which category the action would fall under.

Why not basically describe what is needed to create an action in a NetBeans tutorial or as part of the help topic?
The wizard doesn't create actions for all places to use an action.

Comment 26 Jaroslav Tulach 2008-08-29 08:42:57 UTC
I am not sure I am qualified to write tutorial just for you, but you can try to:
1. create the action using wizard
2. tweak the layer file the way you want to in editor
2a. create a shadow that links to newly create action from the place of the original action
This fix is quite straightforward. It is build around just two concepts: usage of wizard, editing of layer file. 
Simple task for any NetBeans Certified Engineer.
Comment 27 John Baker 2008-08-29 08:57:58 UTC
These have been done:
> 2. tweak the layer file the way you want to in editor
> 2a. create a shadow that links to newly create action from the place of the original action

The problem is the wizard is not suitable for adding an action to a non-Global toolbar.  The section in the Wizard says
"Global toolbar"
Comment 28 John Baker 2008-08-29 09:00:48 UTC
My complaint  that the Wizard is not intuitive and documentation is lacking.  For a new feature there should be better
documentation.  I can file an issue.

Comment 29 John Baker 2008-08-30 06:58:43 UTC
ca286d806605
WhitelistTest no longer lists SQLHistoryAction, so I guess it's fixed now after this change
Comment 30 Quality Engineering 2008-08-30 17:26:21 UTC
Integrated into 'main-golden', available in build *200808301401* on http://bits.netbeans.org/dev/nightly/
Changeset: http://hg.netbeans.org/main/rev/ca286d806605
User: John Baker <jbaker@netbeans.org>
Log: #143060 Startup regression: org.netbeans.modules.db.sql.editor.ui.actions.SQLHistoryAction
Comment 31 John Baker 2008-09-01 07:32:53 UTC
Fix was incomplete
Comment 32 John Baker 2008-09-01 07:55:17 UTC
When I wrapped the alwaysEnabled action in the layer file, at runtime when right-clicking, there was a Mnemonic exception.
So, it appears I need to set the mnemonics again even though mnemonics are set in the layer file.

java.lang.NullPointerException
	at org.openide.awt.Mnemonics.findMnemonicAmpersand(Mnemonics.java:169)
	at org.openide.awt.AlwaysEnabledAction.extractCommonAttribute(AlwaysEnabledAction.java:91)
	at org.openide.awt.AlwaysEnabledAction.getValue(AlwaysEnabledAction.java:78)
	at javax.swing.AbstractButton.setMnemonicFromAction(AbstractButton.java:1236)
	at javax.swing.AbstractButton.configurePropertiesFromAction(AbstractButton.java:1140)
	at javax.swing.JMenuItem.configurePropertiesFromAction(JMenuItem.java:359)
	at javax.swing.AbstractButton.setAction(AbstractButton.java:1087)
	at javax.swing.JMenuItem.<init>(JMenuItem.java:122)
	at org.netbeans.modules.editor.NbEditorKit$NbBuildPopupMenuAction.createLocalizedMenuItem(NbEditorKit.java:402)
Comment 33 Andrei Badea 2008-09-01 14:25:59 UTC
As the owner of the module in question, I oppose to fixing this issue using alwaysEnabled() for reasons explained in
desc18 and desc22. I would also want to get John's agreement to back out changeset #ca286d806605.
Comment 34 Andrei Badea 2008-09-01 14:27:07 UTC
BTW the information that is missing in the issue is one that would convince me that this is a real issue.
Comment 35 Andrei Badea 2008-09-01 14:37:35 UTC
And I still believe the core problem (if there is a problem at all) is tracked by issue 133009.
Comment 36 Andrei Badea 2008-09-01 15:49:38 UTC
#ca286d806605 already reverted by John in issue 145751.
Comment 37 Alexander Kouznetsov 2008-09-03 14:47:21 UTC
This class was not being loaded in 080831 but is being loaded in 080902 again.
Comment 38 Andrei Badea 2008-10-15 14:03:16 UTC
Marking as P4 according to issue 143075 desc7.
Comment 39 Jiri Rechtacek 2009-07-01 07:57:26 UTC
Reassigned to new owner.
Comment 40 Jaroslav Tulach 2009-08-04 07:25:16 UTC
Fixed by integration of issue 152576. Additional test added as ergonomics#d70f3c8ce2bf
Comment 41 Quality Engineering 2009-08-06 17:44:20 UTC
Integrated into 'main-golden', will be available in build *200908061401* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/d70f3c8ce2bf
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #143060: Don't load actions just to assign them a shortcut
Comment 42 Jesse Glick 2009-08-07 00:24:38 UTC
Thanks for the blacklist addition, though I still think something is fishy here.

From reading the code, it seems that SQLHistoryAction, as a SQLExecutionBaseAction, is not usable as a singleton action
at all; actionPerformed specifically does nothing, and it is marked a ContextAwareAction. In other words, it would be
appropriate in an editor popup, perhaps an editor toolbar, somewhere where a context will always be passed - but not as
a globally registered action (such as in the Shortcuts folder, which triggered this bug report before issue #152576 was
fixed).

If I am wrong and this action really works as a non-CAA, then using Actions.alwaysEnabled as jtulach suggested would be
more appropriate. The fact that it sometimes calls setEnabled(false) is not a big deal - this call will be honored once
the real action is loaded; it just means that the _first_ time the action is invoked in a given IDE session, it is
possible that sqlExecution.isExecuting(), which it should handle gracefully (e.g. do nothing or beep); subsequently it
will enable & disable normally.

abadea's DRY objection to Actions.alwaysEnabled in desc22 is based on a misunderstanding, by the way - any attributes of
the action such as display name, icon, etc. which are defined statically in the layer need not additionally be defined
in the Action subclass, since the proxy Action that is loaded from
Actions/System/org-netbeans-modules-db-sql-editor-ui-actions-SQLHistoryAction.instance will offer these static values as
defaults (which is why it is permitted for the delegate to be a bare ActionListener rather than a full Action).
Comment 43 Andrei Badea 2009-08-07 09:18:06 UTC
This smells indeed. All subclasses of SQLExecutionBaseAction are only intended to be used as CAA's -- they need the
SQLExecution context. SQLHistoryAction seems to need a SQLExecution too, but it only uses it to get access to the editor
pane corresponding to the editor toolbar from where the action was invoked, and then it seems to ignore this editor pane
(see SQLHistoryPanel in db.core) and uses EditorRegistry.lastFocusedComponent(). 

While it seems the SQLHistoryAction could be made global, I'm not sure it would be practical. Having access to the
SQLExecution context of the current editor is generally useful. Let's consider SQLHistoryAction non-global and CAA only
for the purpose of this discussion.

Jesse, are you saying that non-global actions such as SQLExecutionBaseAction's subclasses should not be registered in
the Shortcuts folder? I did so because I didn't know another way to assign the action a keyboard shortcut. What's the
right way to do it then?
Comment 44 Jaroslav Tulach 2009-08-07 10:12:15 UTC
If you do not need to shortcut to be changable (by user or by different profiles), then you can place your keystroke, 
key and action directly to JComponent.getInputMap() and JComponent.getActionMap(). If you think this would be more 
appropriate in this case then reopen and let new owners fix this.
Comment 45 Andrei Badea 2009-08-07 12:29:27 UTC
The user should be able to change the shortcut, just as it is the case for most actions.
Comment 46 Jesse Glick 2009-08-07 16:48:27 UTC
As far as I know the Shortcuts folder is intended only for global actions with no context. If you are interested in
registering an action for a particular editor type with a particular default accelerator, you will need to use some
editor-specific registration that I do not know much more about.

http://deadlock.netbeans.org/hudson/job/nbms-and-javadoc/lastStableBuild/artifact/nbbuild/build/generated/layers.txt

shows items such as

Editors/text/x-java/Keybindings/NetBeans/Defaults/o-n-m-editor-java-keybindings.xml

which I presume is the format you would use. But best to ask editor developers if in doubt. There seems to be little
relevant information at

http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-editor-settings/overview-summary.html