Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Compare » [Bug?] NullPointerException in ReferenceChangeMerger#moveElement
[Bug?] NullPointerException in ReferenceChangeMerger#moveElement [message #1199265] Wed, 20 November 2013 19:23 Go to next message
Alan DW is currently offline Alan DW
Messages: 105
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
Re: [Bug?] NullPointerException in ReferenceChangeMerger#moveElement [message #1200456 is a reply to message #1199265] Thu, 21 November 2013 08:49 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
Hi Alan,

Could you provide us with sample models to reproduce this? Please attach them to a bugzilla entry for this NPE : https://bugs.eclipse.org/bugs/enter_bug.cgi?product=EMFCompare&component=Core .

NullPointerExceptions are easy to "fix" blindly... but without reproducing them we can never be sure that the fix is coherent and that it won't hide another issue deeper down.

Laurent Goubet
Obeo
Re: [Bug?] NullPointerException in ReferenceChangeMerger#moveElement [message #1200653 is a reply to message #1200456] Thu, 21 November 2013 10:45 Go to previous messageGo to next message
Alan DW is currently offline Alan DW
Messages: 105
Registered: March 2012
Senior Member
Hi,

thanks for your response. I've created the bug report here and I've attached the required *.ecore and *.xmi models to reproduce it, along with my relevant code and the stack trace that I'm getting. I hope this helps you to figure out what is happening, and I really hope that you can reproduce and fix this error because this currently acts as a show-stopper in my project. If you need any further information, please let me know.

Thank you,


Alan
Re: [Bug?] NullPointerException in ReferenceChangeMerger#moveElement [message #1218597 is a reply to message #1200653] Fri, 29 November 2013 10:49 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
Hi Alan,

Sorry for the late answer and thanks for the test cases, we'll be able to look into reproducing this now Smile.

Laurent Goubet
Obeo
Re: [Bug?] NullPointerException in ReferenceChangeMerger#moveElement [message #1218718 is a reply to message #1218597] Fri, 29 November 2013 11:59 Go to previous messageGo to next message
Alan DW is currently offline Alan DW
Messages: 105
Registered: March 2012
Senior Member
Hi Laurent,

thank you for looking into it. This NullPointerException is really stopping my project right now, so I hope that you can reproduce it. If you need any further information, please let me know.

Thank you,


Alan
Re: [Bug?] NullPointerException in ReferenceChangeMerger#moveElement [message #1219501 is a reply to message #1218718] Wed, 04 December 2013 10:09 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
Hi Alan,

The Team is currently quite overloaded wtih enhancements on the git support for model comparisons. We'll look into this bug asap afterwards and keep you informed (you could also look into fixing it yourself and providing us with the patch through gerrit if you are really in a hurry).

Laurent Goubet
Obeo
Re: [Bug?] NullPointerException in ReferenceChangeMerger#moveElement [message #1219508 is a reply to message #1199265] Wed, 04 December 2013 10:39 Go to previous message
Alan DW is currently offline Alan DW
Messages: 105
Registered: March 2012
Senior Member
Hi Laurent,

thank you for keeping me informed. I'm currently working on different aspects of the project that don't require EMFCompare (yet), so it's not that urgent right now. If I have accomplished all other project goals and the only thing that's left undone is the three-way-compare (I guess it will take me at least 2 or 3 months to get to that point), then I'll look into the source code myself, thanks for the GIT link.


Best regards,


Alan
Previous Topic:How to open a compare editor with a comparison object
Next Topic:Does EMF Compare supports feature maps?
Goto Forum:
  


Current Time: Sun Oct 26 08:03:29 GMT 2014

Powered by FUDForum. Page generated in 0.01771 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software