Uploaded image for project: 'Tools (JBoss Tools)'
  1. Tools (JBoss Tools)
  2. JBIDE-21668

Fix collection setters in ResourcesUIModel

    XMLWordPrintable

Details

    • Task
    • Resolution: Obsolete
    • Major
    • 4.4.x
    • 4.4.0.Alpha1
    • openshift
    • None
    • 8

    Description

      Created as follow up to JBIDE-21590.
      Collections setters in ResourcesUIModel, for instance

      	public void setBuildConfigs(Collection<IResourceUIModel> buildConfigs) {
      		firePropertyChange(PROP_BUILD_CONFIGS, resources.get(ResourceKind.BUILD_CONFIG), resources.put(ResourceKind.BUILD_CONFIG, new ArrayList<>(buildConfigs)));
      	}
      

      fire incorrect newValue object, because java.util.Map.put(key, value) returns old object associated with the key, not the one just set.

      At this moment, this does not create any bugs, because these setters are still not used, all changes go through ResourcesUIModel.add, ResourcesUIModel.remove, ResourcesUIModel.update that have correct notification. But bugs may appear as soon as collection setters are used, so that they better be fixed, for instance this way :

      	public void setBuildConfigs(Collection<IResourceUIModel> buildConfigs) {
      		setResourcesForKind(buildConfigs, ResourceKind.BUILD_CONFIG);
      	}
      
      	private void setResourcesForKind(Collection<IResourceUIModel> list, String kind) {
      		List<IResourceUIModel> oldList = resources.get(kind);
      		List<IResourceUIModel> newList = new ArrayList<IResourceUIModel>(list);
      		resources.put(kind, newList);
      		firePropertyChange(getProperty(kind), oldList, newList);
      	}
      

      and with use of private setResourcesForKind all other setters will remain one-liners.

      Attachments

        Issue Links

          Activity

            People

              scabanovich Viacheslav Kabanovich (Inactive)
              scabanovich Viacheslav Kabanovich (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: