Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [EMF Compare]MatchEngine NPE bug
[EMF Compare]MatchEngine NPE bug [message #121761] Fri, 02 May 2008 15:41 Go to next message
David Michonneau is currently offline David MichonneauFriend
Messages: 85
Registered: July 2009
Member
Hi,

It seems there is a bug in the GenericMatchEngine.hasSameUri() code:

if one of the EObject returns an empty eResource() (which happens for some
objects in my model), it throws a NPE. I suggest the following fix below.

Thanks,

David
/**

* Checks wether the two given {@link EObject} have the same URI.

*

* @param obj1

* First of the two {@link EObject} we're comparing.

* @param obj2

* Second {@link EObject} we're comparing.

* @return <code>True</code> if the {@link EObject}s have the same URI,
<code>False</code> otherwise.

*/

private boolean hasSameUri(EObject obj1, EObject obj2) {

if ( obj1.eResource() == obj2.eResource() ) // null==null returns true

return true;

if ( obj1.eResource() == null || obj2.eResource() == null ) // if one of
them is null and not the other return false

return false;

return
obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));

}
Re: [EMF Compare]MatchEngine NPE bug [message #121789 is a reply to message #121761] Fri, 02 May 2008 15:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Guys,

Just a suggestion. Calling eResource can potentially be quite
expensive, since you have to traverse all the way to the root, so I'd
suggest calling it once and using the returned value multiple times.


David Michonneau wrote:
> Hi,
>
> It seems there is a bug in the GenericMatchEngine.hasSameUri() code:
>
> if one of the EObject returns an empty eResource() (which happens for some
> objects in my model), it throws a NPE. I suggest the following fix below.
>
> Thanks,
>
> David
> /**
>
> * Checks wether the two given {@link EObject} have the same URI.
>
> *
>
> * @param obj1
>
> * First of the two {@link EObject} we're comparing.
>
> * @param obj2
>
> * Second {@link EObject} we're comparing.
>
> * @return <code>True</code> if the {@link EObject}s have the same URI,
> <code>False</code> otherwise.
>
> */
>
> private boolean hasSameUri(EObject obj1, EObject obj2) {
>
> if ( obj1.eResource() == obj2.eResource() ) // null==null returns true
>
> return true;
>
> if ( obj1.eResource() == null || obj2.eResource() == null ) // if one of
> them is null and not the other return false
>
> return false;
>
> return
> obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>
> }
>
>
>
Re: [EMF Compare]MatchEngine NPE bug [message #122141 is a reply to message #121761] Wed, 07 May 2008 08:57 Go to previous message
Cedric Brun is currently offline Cedric BrunFriend
Messages: 431
Registered: July 2009
Senior Member
Hi David,

Thanks (again ;) ) for your feedback, we'll apply the fix ASAP.

Cédric



David Michonneau wrote:

> Hi,
>
> It seems there is a bug in the GenericMatchEngine.hasSameUri() code:
>
> if one of the EObject returns an empty eResource() (which happens for some
> objects in my model), it throws a NPE. I suggest the following fix below.
>
> Thanks,
>
> David
> /**
>
> * Checks wether the two given {@link EObject} have the same URI.
>
> *
>
> * @param obj1
>
> * First of the two {@link EObject} we're comparing.
>
> * @param obj2
>
> * Second {@link EObject} we're comparing.
>
> * @return <code>True</code> if the {@link EObject}s have the same URI,
> <code>False</code> otherwise.
>
> */
>
> private boolean hasSameUri(EObject obj1, EObject obj2) {
>
> if ( obj1.eResource() == obj2.eResource() ) // null==null returns true
>
> return true;
>
> if ( obj1.eResource() == null || obj2.eResource() == null ) // if one of
> them is null and not the other return false
>
> return false;
>
> return
>
obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>
> }


http://cedric.brun.io news and articles on eclipse and eclipse modeling.
Re: [EMF Compare]MatchEngine NPE bug [message #617987 is a reply to message #121761] Fri, 02 May 2008 15:57 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30996
Registered: July 2009
Senior Member
Guys,

Just a suggestion. Calling eResource can potentially be quite
expensive, since you have to traverse all the way to the root, so I'd
suggest calling it once and using the returned value multiple times.


David Michonneau wrote:
> Hi,
>
> It seems there is a bug in the GenericMatchEngine.hasSameUri() code:
>
> if one of the EObject returns an empty eResource() (which happens for some
> objects in my model), it throws a NPE. I suggest the following fix below.
>
> Thanks,
>
> David
> /**
>
> * Checks wether the two given {@link EObject} have the same URI.
>
> *
>
> * @param obj1
>
> * First of the two {@link EObject} we're comparing.
>
> * @param obj2
>
> * Second {@link EObject} we're comparing.
>
> * @return <code>True</code> if the {@link EObject}s have the same URI,
> <code>False</code> otherwise.
>
> */
>
> private boolean hasSameUri(EObject obj1, EObject obj2) {
>
> if ( obj1.eResource() == obj2.eResource() ) // null==null returns true
>
> return true;
>
> if ( obj1.eResource() == null || obj2.eResource() == null ) // if one of
> them is null and not the other return false
>
> return false;
>
> return
> obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>
> }
>
>
>
Re: [EMF Compare]MatchEngine NPE bug [message #618014 is a reply to message #121761] Wed, 07 May 2008 08:57 Go to previous message
Cedric Brun is currently offline Cedric BrunFriend
Messages: 431
Registered: July 2009
Senior Member
Hi David,

Thanks (again ;) ) for your feedback, we'll apply the fix ASAP.

Cédric



David Michonneau wrote:

> Hi,
>
> It seems there is a bug in the GenericMatchEngine.hasSameUri() code:
>
> if one of the EObject returns an empty eResource() (which happens for some
> objects in my model), it throws a NPE. I suggest the following fix below.
>
> Thanks,
>
> David
> /**
>
> * Checks wether the two given {@link EObject} have the same URI.
>
> *
>
> * @param obj1
>
> * First of the two {@link EObject} we're comparing.
>
> * @param obj2
>
> * Second {@link EObject} we're comparing.
>
> * @return <code>True</code> if the {@link EObject}s have the same URI,
> <code>False</code> otherwise.
>
> */
>
> private boolean hasSameUri(EObject obj1, EObject obj2) {
>
> if ( obj1.eResource() == obj2.eResource() ) // null==null returns true
>
> return true;
>
> if ( obj1.eResource() == null || obj2.eResource() == null ) // if one of
> them is null and not the other return false
>
> return false;
>
> return
>
obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>
> }


http://cedric.brun.io news and articles on eclipse and eclipse modeling.
Previous Topic:Graphical XML Schema Editor for 3.3.2?
Next Topic:[CDO 0.8.0] Transaction/Objects scope
Goto Forum:
  


Current Time: Mon Mar 30 23:59:24 GMT 2020

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

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

Back to the top