Skip to content

Commit c5ec8ae

Browse files
committed
Issue #51 - Fixed mutation of allParents in commonAncestor method.
1 parent 07e3805 commit c5ec8ae

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

org.modeldriven.alf/src/org/modeldriven/alf/syntax/common/impl/InternalElementReferenceImpl.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,6 @@ public boolean equals(Object object) {
662662
}
663663
}
664664

665-
// @Override
666-
// public boolean conformsTo(ElementReference type) {
667-
// return this.isClassifier() && type != null &&
668-
// (type.getImpl().isAny() ||
669-
// this.equals(type) ||
670-
// type.getImpl().isContainedIn(this.allParents()));
671-
// }
672-
//
673665
@Override
674666
public int hashCode() {
675667
SyntaxElement element = this.getSelf().getElement();

org.modeldriven.alf/src/org/modeldriven/alf/syntax/units/impl/ClassifierDefinitionImpl.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2011, 2017 Data Access Technologies, Inc. (Model Driven Solutions)
2+
* Copyright 2011, 2018 Data Access Technologies, Inc. (Model Driven Solutions)
33
* All rights reserved worldwide. This program and the accompanying materials
44
* are made available for use under the terms of the GNU General Public License
55
* (GPL) version 3 that accompanies this distribution and is available at
@@ -385,15 +385,17 @@ public static ElementReference commonAncestor(Collection<ElementReference> class
385385
if (classifier == null || classifier.getImpl().isAny()) {
386386
return classifier;
387387
}
388+
// Note: allParents may be cached, so it should not be mutated.
388389
Collection<ElementReference> ancestors = classifier.getImpl().allParents();
389-
ancestors.add(classifier);
390390
if (isFirst) {
391+
commonAncestors.add(classifier);
391392
commonAncestors.addAll(ancestors);
392393
isFirst = false;
393394
} else {
394-
for (Object commonAncestor: commonAncestors.toArray()) {
395-
if (!(((ElementReference)commonAncestor).getImpl().
396-
isContainedIn(ancestors))) {
395+
for (Object object: commonAncestors.toArray()) {
396+
ElementReference commonAncestor = (ElementReference)object;
397+
if (!commonAncestor.getImpl().equals(classifier) &&
398+
!commonAncestor.getImpl().isContainedIn(ancestors)) {
397399
commonAncestors.remove(commonAncestor);
398400
}
399401
}
@@ -406,7 +408,8 @@ public static ElementReference commonAncestor(Collection<ElementReference> class
406408
// Remove any common ancestors that are parents of other common
407409
// ancestors.
408410
for (Object ancestor: commonAncestors.toArray()) {
409-
Collection<ElementReference> parents = ((ElementReference)ancestor).getImpl().parents();
411+
Collection<ElementReference> parents =
412+
((ElementReference)ancestor).getImpl().parents();
410413
for (ElementReference parent: parents) {
411414
commonAncestors.remove(parent);
412415
}

0 commit comments

Comments
 (0)