[ 
https://issues.apache.org/jira/browse/NETBEANS-4754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17187970#comment-17187970
 ] 

Eirik Bakke commented on NETBEANS-4754:
---------------------------------------

That might be one way to fix it, but I don't understand the 
ContextManager/ContextAction code well enough to give an opinion here. Another 
question: Is it actually necessary to cache instDelegate here? Is the delegate0 
method expected to be called every time the context changes, or only when the 
user invokes the action?

> it's a job of the ctx aware instance to monitor the data changes
Which instance are you referring to here? Which class?

Another, possibly related problem: if you put the action in question in the 
toolbar, its enabled/disabled state does not update properly when focus is 
shifted from the TopComponent that provides the context object to, say, the 
"Files" sidebar tab. I'm not sure this would be fixed by making changes in 
delegate0.

It's been hard to debug this, as I can only reproduce the problem in my 
platform app, and not in a standalone NetBeans Platform application. There are 
a lot of weak references in this code (not just in instDelegate, but e.g. in 
ContextManager.LSet), which makes references come and go depending on when 
garbage collection is done.


> Action gets called with wrong context until garbage collection
> --------------------------------------------------------------
>
>                 Key: NETBEANS-4754
>                 URL: https://issues.apache.org/jira/browse/NETBEANS-4754
>             Project: NetBeans
>          Issue Type: Bug
>          Components: platform - Actions
>    Affects Versions: 12.0
>         Environment: NetBeans Platform application running on NetBeans 
> Platform 12.0 on Windows 10 / Java 13.0.2.
>            Reporter: Eirik Bakke
>            Assignee: Svatopluk Dedic
>            Priority: Major
>
> My NetBeans Platform application has an action declared as follows:
> {code:java}
> @ActionID(category = "Ultorg", id = "com.ultorg.actionids.FieldsAction")
> @ActionRegistration(displayName = "#CTL_FieldsAction")
> @Messages("CTL_FieldsAction=Fields & Joins...")
> public class FieldsAction implements ActionListener {
>   private final ToolboxInvoker invoker;
>   public FieldsAction(ToolboxInvoker invoker) {
>     Preconditions.checkNotNull(invoker);
>     this.invoker = invoker;
>   }
>   @Override
>   public void actionPerformed(ActionEvent e) {
>     invoker.invoke();
>   }
> }
> {code}
> The ToolboxInvoker context is provided by the lookup of a custom TopComponent 
> implementation. When I have multiple such TopComponent tabs open, switching 
> between them, and invoking the action above with a keyboard shortcut, the 
> wrong FieldsAction instance will occasionally be called (i.e. an instance 
> with the wrong ToolboxInvoker context).
> After some debugging, the problem seems to be caused by 
> https://github.com/apache/netbeans/pull/652 , specifically by 
> ContextAction.delegate0 assuming that instDelegate can be used as a cached 
> value without checking whether the lookup (data parameter) has changed. Or 
> perhaps instDelegate was supposed to be cleared elsewhere whenever the lookup 
> changes--but this is not happening properly.
> Because the instDelegate field holds only weak references, the buggy state 
> only lasts until the next garbage collection.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to