Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-4754

Action gets called with wrong context until garbage collection

    XMLWordPrintableJSON

Details

    • Bug
    • Status: In Progress
    • Major
    • Resolution: Unresolved
    • 12.0
    • None
    • platform - Actions
    • None
    • NetBeans Platform application running on NetBeans Platform 12.0 on Windows 10 / Java 13.0.2.

    Description

      My NetBeans Platform application has an action declared as follows:

      @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();
        }
      }
      

      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.

      Attachments

        1. netbeans-4754-eiriktest.patch
          3 kB
          Eirik Bakke

        Issue Links

          Activity

            People

              sdedic Svatopluk Dedic
              ebakke Eirik Bakke
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: