diff options
author | Christian W. Damus | 2017-03-07 19:00:45 +0000 |
---|---|---|
committer | Christian W. Damus | 2017-03-08 19:52:19 +0000 |
commit | dab1a9e471d987c2059b365006190bd68c8c3487 (patch) | |
tree | cb0a28badbc98e813ce4394d4b76a8679effa5d7 | |
parent | 3a0f0a4912363472b7df545beb453c11545c15f3 (diff) | |
download | org.eclipse.papyrus-rt-dab1a9e471d987c2059b365006190bd68c8c3487.tar.gz org.eclipse.papyrus-rt-dab1a9e471d987c2059b365006190bd68c8c3487.tar.xz org.eclipse.papyrus-rt-dab1a9e471d987c2059b365006190bd68c8c3487.zip |
Fix Findbugs issues (they are actual bugs) in inheritance-related code.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=510323
Change-Id: Ie29459cecfe82674d3e00e0f04b3bc386ffbdb31
5 files changed, 27 insertions, 14 deletions
diff --git a/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/internal/defaultlanguage/DefaultLanguageService.java b/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/internal/defaultlanguage/DefaultLanguageService.java index a8763ffe6..4954c9642 100644 --- a/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/internal/defaultlanguage/DefaultLanguageService.java +++ b/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/internal/defaultlanguage/DefaultLanguageService.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014, 2016 CEA LIST, Christian W. Damus, and others. + * Copyright (c) 2014, 2017 CEA LIST, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,7 +8,7 @@ * * Contributors: * CEA LIST - Initial API and implementation - * Christian W. Damus - bugs 476984, 501119 + * Christian W. Damus - bugs 476984, 501119, 510323 *****************************************************************************/ package org.eclipse.papyrusrt.umlrt.core.internal.defaultlanguage; @@ -404,7 +404,7 @@ public class DefaultLanguageService extends PlatformObject implements IDefaultLa if ((result == null) || result.getContents().isEmpty() || !result.getErrors().isEmpty()) { // Resource diagnostics typically are exceptions - Throwable exception = result.getErrors().stream() + Throwable exception = (result == null) ? null : result.getErrors().stream() .filter(Throwable.class::isInstance).map(Throwable.class::cast) .findAny().orElse(null); throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to load default language resource: " + uri, exception)); diff --git a/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/types/advice/ProtocolContainerEditHelperAdvice.java b/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/types/advice/ProtocolContainerEditHelperAdvice.java index 3ab308eb8..d7ac29075 100644 --- a/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/types/advice/ProtocolContainerEditHelperAdvice.java +++ b/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/types/advice/ProtocolContainerEditHelperAdvice.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2015, 2016 CEA LIST, Christian W. Damus, and others. + * Copyright (c) 2015, 2017 CEA LIST, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,7 +8,7 @@ * * Contributors: * CEA LIST - initial API and implementation - * Christian W. Damus - bugs 497742, 479425 + * Christian W. Damus - bugs 497742, 479425, 510323 * *****************************************************************************/ package org.eclipse.papyrusrt.umlrt.core.types.advice; @@ -229,7 +229,7 @@ public class ProtocolContainerEditHelperAdvice extends AbstractEditHelperAdvice @SuppressWarnings("unchecked") List<? extends EObject> realContents = (List<? extends EObject>) realTarget.eGet(request.getFeature()); List<EObject> newValue = new ArrayList<>(realContents); - newValue.remove(dropped); // In case of move within same parent + newValue.removeAll(dropped); // In case of move within same parent int realDropIndex = newValue.indexOf(request.getElementToEdit()); // There is no such thing as an AddRequest for inserting objects into a diff --git a/plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/internal/facade/impl/FacadeObjectImpl.java b/plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/internal/facade/impl/FacadeObjectImpl.java index 6e2d41d0f..fb4e7a289 100644 --- a/plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/internal/facade/impl/FacadeObjectImpl.java +++ b/plugins/umlrt/profile/org.eclipse.papyrusrt.umlrt.uml/src/org/eclipse/papyrusrt/umlrt/uml/internal/facade/impl/FacadeObjectImpl.java @@ -594,9 +594,7 @@ public abstract class FacadeObjectImpl extends MinimalEObjectImpl.Container impl } } - if (insertion >= 0) { - list.facadeAdd(insertion, object); - } + list.facadeAdd(insertion, object); } @SuppressWarnings("unchecked") diff --git a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/copy/UmlRTPasteStrategy.java b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/copy/UmlRTPasteStrategy.java index 771cd67f9..f9bdac12b 100644 --- a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/copy/UmlRTPasteStrategy.java +++ b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/copy/UmlRTPasteStrategy.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2015 CEA LIST. + * Copyright (c) 2015, 2017 CEA LIST, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -9,6 +9,7 @@ * Contributors: * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - + * Christian W. Damus - bug 510323 *****************************************************************************/ package org.eclipse.papyrusrt.umlrt.tooling.diagram.common.copy; @@ -315,9 +316,10 @@ public class UmlRTPasteStrategy extends AbstractPasteStrategy implements IPasteS callEventMoveCommand = getEditCommand(moveRequest, container); } - if (!callEventMoveCommand.canExecute()) { + if ((callEventMoveCommand != null) && !callEventMoveCommand.canExecute()) { callEventMoveCommand = null; } + return callEventMoveCommand; } @@ -367,7 +369,7 @@ public class UmlRTPasteStrategy extends AbstractPasteStrategy implements IPasteS */ @Override public void prepare(final PapyrusClipboard<Object> papyrusClipboard, final Collection<EObject> selection) { - Map<Object, IClipboardAdditionalData> mapCopyToClipboardAdditionalData = new HashMap<Object, IClipboardAdditionalData>(); + Map<Object, IClipboardAdditionalData> mapCopyToClipboardAdditionalData = new HashMap<>(); for (Iterator<EObject> iterator = papyrusClipboard.iterateOnSource(); iterator.hasNext();) { EObject eObjectSource = iterator.next(); diff --git a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/internal/handlers/OverrideDeleteSourceProvider.java b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/internal/handlers/OverrideDeleteSourceProvider.java index 2367760a8..1b219ad8e 100644 --- a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/internal/handlers/OverrideDeleteSourceProvider.java +++ b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/internal/handlers/OverrideDeleteSourceProvider.java @@ -19,6 +19,7 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.AbstractSourceProvider; import org.eclipse.ui.ISources; @@ -41,7 +42,7 @@ public class OverrideDeleteSourceProvider extends AbstractSourceProvider { private static List<OverrideDeleteSourceProvider> instances = new ArrayList<>(1); - private ISelection selection; + private ISelection selection = StructuredSelection.EMPTY; public OverrideDeleteSourceProvider() { super(); @@ -69,6 +70,10 @@ public class OverrideDeleteSourceProvider extends AbstractSourceProvider { instances.remove(this); } + void setSelection(ISelection selection) { + this.selection = (selection == null) ? StructuredSelection.EMPTY : selection; + } + static boolean setEnabled(boolean enableOverride, ISelection selection) { boolean result = overrideEnabled.compareAndSet(!enableOverride, enableOverride); @@ -77,7 +82,15 @@ public class OverrideDeleteSourceProvider extends AbstractSourceProvider { // Let the active menu selection be defined regardless of whether there // is a menu showing so that our handler can actually use that variable // for activation to effect its override when triggered by the key binding - instances.forEach(p -> p.fireSourceChanged(ISources.ACTIVE_MENU, ISources.ACTIVE_MENU_SELECTION_NAME, selection)); + instances.forEach(p -> { + try { + p.setSelection(selection); + p.fireSourceChanged(ISources.ACTIVE_MENU, ISources.ACTIVE_MENU_SELECTION_NAME, selection); + } finally { + // Don't leak any selected objects + p.setSelection(null); + } + }); } instances.forEach(p -> p.fireSourceChanged(PRIORITY, OVERRIDE_DELETE, enableOverride)); |