Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Faltermeier2018-03-29 10:13:40 -0400
committerJohannes Faltermeier2018-03-29 10:13:40 -0400
commit7308586ff4e200a2550ffc6bfe0647c1e7aecde4 (patch)
tree18f6805f5a84437447761de25a02f89aba899fd2
parent42dedec5f947619b3dc59199bf067b14353d1066 (diff)
downloadorg.eclipse.emf.edapt-7308586ff4e200a2550ffc6bfe0647c1e7aecde4.tar.gz
org.eclipse.emf.edapt-7308586ff4e200a2550ffc6bfe0647c1e7aecde4.tar.xz
org.eclipse.emf.edapt-7308586ff4e200a2550ffc6bfe0647c1e7aecde4.zip
Bug 526561 - NullPointerException in MoveChecker.getIndex
* Prevent NPE and make sure to stop moves in this case Change-Id: I5fdcc91f4b2bee2a328a3c3c21d4da8c099ab8d0 Signed-off-by: Johannes Faltermeier <jfaltermeier@eclipsesource.com>
-rw-r--r--plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/history/util/MoveChecker.java66
1 files changed, 39 insertions, 27 deletions
diff --git a/plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/history/util/MoveChecker.java b/plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/history/util/MoveChecker.java
index a9b93a8..97e9e8b 100644
--- a/plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/history/util/MoveChecker.java
+++ b/plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/history/util/MoveChecker.java
@@ -47,8 +47,12 @@ public class MoveChecker {
* change or release
*/
public static boolean canBeMoved(List<Change> changes, EObject target) {
- final List<Change> children = getChanges(getChildren(target));
- return canBeMoved(changes, target, children.size());
+ try {
+ final List<Change> children = getChanges(getChildren(target));
+ return canBeMoved(changes, target, children.size());
+ } catch (final IllegalStateException ex) {
+ return false;
+ }
}
/**
@@ -57,33 +61,37 @@ public class MoveChecker {
*/
public static boolean canBeMoved(List<Change> changes, EObject target,
int targetIndex) {
- if (!allowedTarget(changes, target)) {
- return false;
- }
- for (final Change change : changes) {
- final EObject source = change.eContainer();
- final int sourceIndex = getIndex(change);
-
- if (source == target && sourceIndex == targetIndex) {
- // nothing has to be done
- } else if (before(source, sourceIndex, target, targetIndex)) {
- final List<Change> difference = getDifference(source,
- sourceIndex + 1, target, targetIndex);
- difference.removeAll(changes);
- if (DependencyChecker.depends(difference, Collections
- .singletonList(change))) {
- return false;
- }
- } else {
- final List<Change> difference = getDifference(target, targetIndex,
- source, sourceIndex - 1);
- difference.removeAll(changes);
- if (DependencyChecker.depends(change, difference)) {
- return false;
+ try {
+ if (!allowedTarget(changes, target)) {
+ return false;
+ }
+ for (final Change change : changes) {
+ final EObject source = change.eContainer();
+ final int sourceIndex = getIndex(change);
+
+ if (source == target && sourceIndex == targetIndex) {
+ // nothing has to be done
+ } else if (before(source, sourceIndex, target, targetIndex)) {
+ final List<Change> difference = getDifference(source,
+ sourceIndex + 1, target, targetIndex);
+ difference.removeAll(changes);
+ if (DependencyChecker.depends(difference, Collections
+ .singletonList(change))) {
+ return false;
+ }
+ } else {
+ final List<Change> difference = getDifference(target, targetIndex,
+ source, sourceIndex - 1);
+ difference.removeAll(changes);
+ if (DependencyChecker.depends(change, difference)) {
+ return false;
+ }
}
}
+ return true;
+ } catch (final IllegalStateException ex) {
+ return false;
}
- return true;
}
/**
@@ -152,7 +160,8 @@ public class MoveChecker {
difference.addAll(changes);
difference.addAll(getDifference(source.eContainer(),
source instanceof Delete ? getIndex(source)
- : getIndex(source) + 1, target, targetIndex));
+ : getIndex(source) + 1,
+ target, targetIndex));
}
return difference;
}
@@ -186,6 +195,9 @@ public class MoveChecker {
* Get the index of an element within its container element
*/
private static int getIndex(EObject element) {
+ if (element == null || element.eContainer() == null || element.eContainmentFeature() == null) {
+ throw new IllegalStateException();
+ }
return ((List) element.eContainer().eGet(element.eContainmentFeature()))
.indexOf(element);
}

Back to the top