[Bug?] NullPointerException in ReferenceChangeMerger#moveElement [message #1199265] |
Wed, 20 November 2013 19:23 |
Alan DW Messages: 119 Registered: March 2012 |
Senior Member |
|
|
Hello everyone,
I'm using this little snippet of code to copy all non-conflicting changes from left to right in a given comparison:
/**
* Copies all non-conflicting changes in the given comparison from left to right.
*
* @param comparison
* The comparison to use. Must not be <code>null</code>.
*/
public static void copyAllNonConflictingChangesFromLeftToRight(final Comparison comparison) {
Preconditions.checkNotNull(comparison, "Cannot copy non-conflicting changes from left to right in comparison NULL!");
IMerger.Registry registry = EMFCompareRCPPlugin.getDefault().getMergerRegistry();
IBatchMerger merger = new BatchMerger(registry);
// Construct the predicate
Predicate<? super Diff> predicate = and(fromSide(DifferenceSource.LEFT), not(hasConflict(ConflictKind.REAL, ConflictKind.PSEUDO)));
// Filter out the diff that do not satisfy the predicate
Iterable<Diff> nonConflictualDifferencesFromLeft = filter(comparison.getDifferences(), predicate);
merger.copyAllLeftToRight(nonConflictualDifferencesFromLeft, new BasicMonitor());
}
The main part of this code has actually been taken from the official wiki page, just wrapped into a method for convenience.
However, when I run this code, I get the following stack trace (shortened to the relevant parts):
java.lang.NullPointerException
at org.eclipse.emf.compare.merge.ReferenceChangeMerger.moveElement(ReferenceChangeMerger.java:263)
at org.eclipse.emf.compare.merge.ReferenceChangeMerger.copyLeftToRight(ReferenceChangeMerger.java:119)
at org.eclipse.emf.compare.merge.AbstractMerger.mergeDiff(AbstractMerger.java:132)
at org.eclipse.emf.compare.merge.AbstractMerger.mergeRequires(AbstractMerger.java:111)
at org.eclipse.emf.compare.merge.ReferenceChangeMerger.copyLeftToRight(ReferenceChangeMerger.java:73)
at org.eclipse.emf.compare.merge.AbstractMerger.mergeDiff(AbstractMerger.java:132)
at org.eclipse.emf.compare.merge.AbstractMerger.mergeRequires(AbstractMerger.java:111)
at org.eclipse.emf.compare.merge.ReferenceChangeMerger.copyLeftToRight(ReferenceChangeMerger.java:73)
at org.eclipse.emf.compare.merge.BatchMerger.copyAllLeftToRight(BatchMerger.java:90)
at ComparisonUtils.copyAllNonConflictingChangesFromLeftToRight(ComparisonUtils.java:164)
The exact line in question where the error occurs is:
// If it exists, use the source side's container as reference
if (rightToLeft && valueMatch.getRight() != null) {
targetContainerMatch = comparison.getMatch(valueMatch.getRight().eContainer());
} else if (!rightToLeft && valueMatch.getLeft() != null) { // HERE the NullPointerException occurs, it seems that valueMatch is NULL
targetContainerMatch = comparison.getMatch(valueMatch.getLeft().eContainer());
} else {
// Otherwise, the value we're moving on one side has been removed from its source side.
targetContainerMatch = comparison.getMatch(valueMatch.getOrigin().eContainer());
}
Since this is rather deep down in EMFCompare, I have little idea what this error means or wether or not it was my fault that caused it. Since this is a plain null pointer exception that is not thrown explicitly but is caused by an illegal access on null, I suspect that this is a bug in EMFCompare, but I'm not sure. I'm using EMFCompare v2.1.2. Did an update just minutes ago in an attempt to fix this, but it existed in the previous version and still does in the current version.
The comparison comes from a three-way-compare of three EObject model root elements (not resources), if that happens to be relevant for this cause.
I'd be grateful for any help and/or advice about this. If necessary, I can post some example model XMIs that cause this issue.
Thanks,
Alan
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03234 seconds