Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Langer2017-05-11 12:18:38 +0000
committerPhilip Langer2017-05-23 12:43:10 +0000
commit86e68dcb2059059777fe9d23c9d21f4aa3b4e208 (patch)
tree253181880bc57d01c3ec2213b6c46c62cd11e5c4 /plugins
parent34e8ef08c59acb4b5568c8030dd9ed2b93f6d58c (diff)
downloadorg.eclipse.emf.compare-86e68dcb2059059777fe9d23c9d21f4aa3b4e208.tar.gz
org.eclipse.emf.compare-86e68dcb2059059777fe9d23c9d21f4aa3b4e208.tar.xz
org.eclipse.emf.compare-86e68dcb2059059777fe9d23c9d21f4aa3b4e208.zip
[516484] Fix memory leak in profile migration hook
Bug: 516484 Change-Id: I304019bcd248f05c1dc7dbe15b93cc196f515857 Signed-off-by: Philip Langer <planger@eclipsesource.com>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/ProfileMigrationHook.java35
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/migration/StereotypeApplicationRepair.java34
2 files changed, 36 insertions, 33 deletions
diff --git a/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/ProfileMigrationHook.java b/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/ProfileMigrationHook.java
index 4e50851f4..969e0d6cb 100644
--- a/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/ProfileMigrationHook.java
+++ b/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/ProfileMigrationHook.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016 EclipseSource Services GmbH and others.
+ * Copyright (c) 2016, 2017 EclipseSource Services GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Martin Fleck - initial API and implementation
+ * Philip Langer - bug 516484
*******************************************************************************/
package org.eclipse.emf.compare.uml2.papyrus.internal.hook;
@@ -116,22 +117,26 @@ public class ProfileMigrationHook extends AbstractResourceSetHooks {
}
final StereotypeApplicationRepair repair = new StereotypeApplicationRepair(resource);
- final ZombieStereotypesDescriptor stereotypesDescriptor = repair.repair();
- if (stereotypesDescriptor == null || !stereotypesDescriptor.hasZombies()) {
- return; // nothing to repair
- }
+ try {
+ final ZombieStereotypesDescriptor stereotypesDescriptor = repair.repair();
+ if (stereotypesDescriptor == null || !stereotypesDescriptor.hasZombies()) {
+ return; // nothing to repair
+ }
- // for each schema (missing EPackages) try to repair the respective stereotype applications
- for (final IAdaptable schema : stereotypesDescriptor.getZombieSchemas()) {
- // the stereotype descriptor already provides the most suitable repair action
- // deletion for orphans (stereotypes whose base element is missing)
- // profile migration for zombies (stereotypes whose defining package can not be found)
- final IRepairAction repairAction = stereotypesDescriptor.getSuggestedRepairAction(schema);
- if (repairAction != null) {
- // execute any suggested action
- stereotypesDescriptor.repair(schema, repairAction, new BasicDiagnostic(),
- new NullProgressMonitor());
+ // for each schema (missing EPackages) try to repair the respective stereotype applications
+ for (final IAdaptable schema : stereotypesDescriptor.getZombieSchemas()) {
+ // the stereotype descriptor already provides the most suitable repair action
+ // deletion for orphans (stereotypes whose base element is missing)
+ // profile migration for zombies (stereotypes whose defining package can not be found)
+ final IRepairAction repairAction = stereotypesDescriptor.getSuggestedRepairAction(schema);
+ if (repairAction != null) {
+ // execute any suggested action
+ stereotypesDescriptor.repair(schema, repairAction, new BasicDiagnostic(),
+ new NullProgressMonitor());
+ }
}
+ } finally {
+ repair.dispose();
}
}
}
diff --git a/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/migration/StereotypeApplicationRepair.java b/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/migration/StereotypeApplicationRepair.java
index ce0dc9c61..52cace466 100644
--- a/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/migration/StereotypeApplicationRepair.java
+++ b/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/migration/StereotypeApplicationRepair.java
@@ -10,6 +10,7 @@
* Stefan Dirix - bug 498583
* Laurent Delaigue - bug 498583
* Martin Fleck - bug 515041
+ * Philip Langer - bug 516484
*******************************************************************************/
package org.eclipse.emf.compare.uml2.papyrus.internal.hook.migration;
@@ -66,6 +67,9 @@ public class StereotypeApplicationRepair extends StereotypeApplicationRepairSnip
/** The profile supplier used to find a profile if a package is missing. */
private Object fProfileSupplier;
+ /** The model set used by {@link #repair()} and {@link #dispose()}. */
+ private ModelSetWrapper fModelSet;
+
/**
* Creates a new repair analyzer for zombie and orphan stereotype applications for the given resource.
*
@@ -78,6 +82,9 @@ public class StereotypeApplicationRepair extends StereotypeApplicationRepairSnip
this.fResource = resource;
this.fLabelProviderService = setLabelProviderService(createLabelProviderService());
this.fProfileSupplier = setProfileSupplier(createProfileSupplier());
+ this.fModelSet = new ModelSetWrapper(resource.getResourceSet());
+ // avoid read-only for our resource
+ fModelSet.setReadOnly(resource, Boolean.FALSE);
}
@Override
@@ -97,6 +104,13 @@ public class StereotypeApplicationRepair extends StereotypeApplicationRepairSnip
}
/**
+ * Disposed the instance.
+ */
+ public void dispose() {
+ dispose(this.fModelSet);
+ }
+
+ /**
* Reflectively sets the field with the given name in the super class to the specified fieldValue.
*
* @param fieldName
@@ -255,21 +269,6 @@ public class StereotypeApplicationRepair extends StereotypeApplicationRepairSnip
}
/**
- * Creates a {@link ModelSet} wrapper around the given resource set to be used for profile migration
- * within Eclipse Luna.
- *
- * @param resourceSet
- * resource set containing the resource under repair
- * @return newly created model set wrapper
- */
- protected ModelSet createModelSetWrapper(ResourceSet resourceSet) {
- final ModelSetWrapper modelSet = new ModelSetWrapper(resourceSet);
- // avoid read-only for our resource
- modelSet.setReadOnly(fResource, Boolean.FALSE);
- return modelSet;
- }
-
- /**
* Evaluates whether all necessary fiels have been set successfully and a repair is possible.
*
* @return true if a repair is possible, false otherwise.
@@ -299,9 +298,8 @@ public class StereotypeApplicationRepair extends StereotypeApplicationRepairSnip
}
try {
final ResourceSet resourceSet = fResource.getResourceSet();
- final ModelSet modelSet = createModelSetWrapper(resourceSet);
- setAdapter(modelSet);
- modelSet.getResources().add(fResource);
+ setAdapter(fModelSet);
+ fModelSet.getResources().add(fResource);
final ZombieStereotypesDescriptor stereotypesDescriptor = getZombieStereotypes(fResource);
resourceSet.getResources().add(fResource);
return stereotypesDescriptor;

Back to the top