Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8273283

XXEvent: must not violate contract of copyFor

    XMLWordPrintable

Details

    Description

      doc of Event.copyFor:

      "Creates and returns a copy of this event with the specified event source and target."

      formulated as test (can be run in EventAnyTest):

          @Test
          public void testCopyFor() {
              Object sourceForCopy = new Object();
              Event copiedEvent = event.copyFor(sourceForCopy, event.getTarget());
              assertEquals("copied " + event.getClass().getName() + " must have copied source\n",
                      sourceForCopy, copiedEvent.getSource());
          }

      - fails for TreeItem.TreeModificationEvent, all EditEvents (TreeTable, Tree, List)
      - passes for CheckBoxTreeItem.TreeModificationEvent, ScrollToEvent, SortEvent, Tree/TableColumn.CellEditEvent

      Culprit is a shadowing field source which is returned in the overridden getSource, f.i for ListView.EditEvent:

          final ListView<T> source;

          public EditEvent(ListView<T> source, ..)
               super(source, ..)
               this.source = source;
               ...
           }

           @Override public ListView<T> getSource() {
                  return source;
            }
        
      fix would be to remove the new field and the override. This will break client code relying on the incorrect source being a ListView always - but such code would be plain wrong anyway.

      Attachments

        Issue Links

          Activity

            People

              fastegal Jeanette Winzenburg
              fastegal Jeanette Winzenburg
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: