Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Dirix2016-07-27 12:33:26 -0400
committerLaurent Delaigue2016-07-28 05:01:50 -0400
commitd081f4eadf50462146160d40d1d79b19dbbbe6da (patch)
tree586b2ac96e6022e42052a97135df89c6a9c65489
parent47f29d0f824b6fe77d3ededc55a0fc7a6ba13a21 (diff)
downloadorg.eclipse.emf.compare-d081f4eadf50462146160d40d1d79b19dbbbe6da.tar.gz
org.eclipse.emf.compare-d081f4eadf50462146160d40d1d79b19dbbbe6da.tar.xz
org.eclipse.emf.compare-d081f4eadf50462146160d40d1d79b19dbbbe6da.zip
[498583] Fix NPE during automatic profile migration
Fix the Null Pointer Exception which could occur when the LabelProviderService was not started before the profile migration took place. Also prevent exceptions in repair() from being propagated so that they don't block users and are displayed properly. Bug: 498583 Also-by: Laurent Delaigue <laurent.delaigue@obeo.fr> Signed-off-by: Laurent Delaigue <laurent.delaigue@obeo.fr> Change-Id: Ife0d5c5c101082ea042df8bf455c5a9db117b912
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/migration/StereotypeApplicationRepair.java57
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/migration/UMLLabelProviderService.java4
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/messages.properties3
3 files changed, 54 insertions, 10 deletions
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 744599750..97e3ef621 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
@@ -7,6 +7,8 @@
*
* Contributors:
* Martin Fleck - initial API and implementation
+ * Stefan Dirix - bug 498583
+ * Laurent Delaigue - bug 498583
*******************************************************************************/
package org.eclipse.emf.compare.uml2.papyrus.internal.hook.migration;
@@ -14,12 +16,17 @@ import com.google.common.base.Function;
import java.lang.reflect.Field;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.compare.uml2.papyrus.internal.UMLPapyrusCompareMessages;
+import org.eclipse.emf.compare.uml2.papyrus.internal.UMLPapyrusComparePlugin;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
import org.eclipse.papyrus.uml.modelrepair.internal.stereotypes.StereotypeApplicationRepairSnippet;
import org.eclipse.papyrus.uml.modelrepair.internal.stereotypes.ZombieStereotypesDescriptor;
@@ -57,6 +64,21 @@ public class StereotypeApplicationRepair extends StereotypeApplicationRepairSnip
setProfileSupplier(createProfileSupplier());
}
+ @Override
+ public void dispose(ModelSet modelsManager) {
+ try {
+ LabelProviderService s = (LabelProviderService)getSuperField("labelProviderService"); //$NON-NLS-1$
+ if (s != null) {
+ s.disposeService();
+ }
+ } catch (ServiceException ex) {
+ UMLPapyrusComparePlugin.getDefault().getLog().log(new Status(IStatus.WARNING,
+ UMLPapyrusComparePlugin.PLUGIN_ID, "Unable to dispose Label Provider Service", //$NON-NLS-1$
+ ex));
+ }
+ super.dispose(modelsManager);
+ }
+
/**
* Reflectively sets the field with the given name in the super class to the specified fieldValue.
*
@@ -152,7 +174,15 @@ public class StereotypeApplicationRepair extends StereotypeApplicationRepairSnip
*/
protected LabelProviderService createLabelProviderService() {
// we use a label provider service that does not need any special UI capabilities
- return new UMLLabelProviderService();
+ UMLLabelProviderService umlLabelProviderService = new UMLLabelProviderService();
+ try {
+ umlLabelProviderService.startService();
+ } catch (ServiceException ex) {
+ UMLPapyrusComparePlugin.getDefault().getLog().log(new Status(IStatus.WARNING,
+ UMLPapyrusComparePlugin.PLUGIN_ID, "Unable to start UML Label Provider Service", //$NON-NLS-1$
+ ex));
+ }
+ return umlLabelProviderService;
}
/***
@@ -199,13 +229,24 @@ public class StereotypeApplicationRepair extends StereotypeApplicationRepairSnip
* @return descriptor of zombie and orphan stereotypes
*/
public ZombieStereotypesDescriptor repair() {
- final ResourceSet resourceSet = resource.getResourceSet();
- final ModelSet modelSet = createModelSetWrapper(resourceSet);
- setAdapter(modelSet);
- modelSet.getResources().add(resource);
- final ZombieStereotypesDescriptor stereotypesDescriptor = getZombieStereotypes(resource);
- resourceSet.getResources().add(resource);
- return stereotypesDescriptor;
+ try {
+ final ResourceSet resourceSet = resource.getResourceSet();
+ final ModelSet modelSet = createModelSetWrapper(resourceSet);
+ setAdapter(modelSet);
+ modelSet.getResources().add(resource);
+ final ZombieStereotypesDescriptor stereotypesDescriptor = getZombieStereotypes(resource);
+ resourceSet.getResources().add(resource);
+ return stereotypesDescriptor;
+ // CHECKSTYLE:OFF
+ } catch (Exception e) {
+ // CHECKSTYLE:ON
+ resource.getErrors().add(new ProfileMigrationDiagnostic(UMLPapyrusCompareMessages.getString(
+ "profile.migration.exception", e, resource))); //$NON-NLS-1$
+ UMLPapyrusComparePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
+ UMLPapyrusComparePlugin.PLUGIN_ID, "Exception occurred during profile migration", //$NON-NLS-1$
+ e)); // The exception stack trace will appear in the error log
+ }
+ return null;
}
/**
diff --git a/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/migration/UMLLabelProviderService.java b/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/migration/UMLLabelProviderService.java
index 06dfe43d7..fa86843a5 100644
--- a/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/migration/UMLLabelProviderService.java
+++ b/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/hook/migration/UMLLabelProviderService.java
@@ -31,7 +31,9 @@ class UMLLabelProviderService implements LabelProviderService {
* {@inheritDoc}
*/
public void disposeService() throws ServiceException {
- labelProvider.dispose();
+ if (labelProvider != null) {
+ labelProvider.dispose();
+ }
}
/**
diff --git a/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/messages.properties b/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/messages.properties
index 18ea45385..2c506cb89 100644
--- a/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/messages.properties
+++ b/plugins/org.eclipse.emf.compare.uml2.papyrus/src/org/eclipse/emf/compare/uml2/papyrus/internal/messages.properties
@@ -10,4 +10,5 @@
################################################################################
profile.migration.success = Missing package {0} has been migrated to profile {1}.
-profile.migration.fail = Package {0} could not be migrated, no suitable substitution has been found. \ No newline at end of file
+profile.migration.fail = Package {0} could not be migrated, no suitable substitution has been found.
+profile.migration.exception = An exception occurred during automatic profile migration of resource {1}: {0} \ No newline at end of file

Back to the top