Home » Modeling » Epsilon » Bug in org.eclipse.epsilon.evl.emf.validation
Bug in org.eclipse.epsilon.evl.emf.validation [message #834757] |
Mon, 02 April 2012 07:04  |
Eclipse User |
|
|
|
Hi guys,
there is a bug in org.eclipse.epsilon.evl.emf.validation.CompositeEValidator.java at line 44:
if one of the validators fails none of the remaining validators are invoked because the corresponding expression is not evaluated anymore. This causes a NullPointerException in org.eclipse.epsilon.evl.emf.validation.EvlValidator.java at line 160 when validating the children since the validation results are not initialized.
Just replace the "short-circuit" AND operator (&&) with the normal one (&) to fix it.
Best regards,
Andrey Skorikov
|
|
|
Re: Bug in org.eclipse.epsilon.evl.emf.validation [message #835531 is a reply to message #834757] |
Tue, 03 April 2012 07:06   |
Eclipse User |
|
|
|
Hi Andrey,
Thanks for your tip. However, I don't think that's the cause. This is the code you mention, right?
public boolean validate(EClass class1, EObject object,
DiagnosticChain diagnostics, Map<Object, Object> context)
{
boolean validate = true;
for (EValidator validator : delegates) {
validate = validate && validator.validate(class1, object, diagnostics, context);
}
return validate;
}
That's a regular "foreach" Java 6 loop. Even if validate becomes false, we will loop through all the delegates anyway. Switching from && to & would have no effect in this case.
Are you having problems with some EVL script in particular?
Cheers,
Antonio
|
|
|
Re: Bug in org.eclipse.epsilon.evl.emf.validation [message #835542 is a reply to message #835531] |
Tue, 03 April 2012 07:25   |
Eclipse User |
|
|
|
Hi Antonio,
thanks for the fast reply! Surely, the following expression is evaluated for every delegate in the collection:
validate = validate && validator.validate(class1, object, diagnostics, context)
However, it does not hold for the following subexpression:
validator.validate(class1, object, diagnostics, context)
because when "validate" becomes false, the whole expression must yield false, so there is no need to evaluate the remaining subexpression. That's the idea behind the "short-circuit" AND operator. Unfortunately, the expression has to be evaluated in any case because of its side effects, otherwise we'll get exceptions later.
Cheers,
Andrey
|
|
| | |
Re: Bug in org.eclipse.epsilon.evl.emf.validation [message #835741 is a reply to message #835730] |
Tue, 03 April 2012 12:01   |
Eclipse User |
|
|
|
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Antonio,<br>
<br>
I'm not sure the full context, but EMF's generated validators
generally take this kind of approach:<br>
<blockquote><small> public boolean validateEClass(EClass eClass,
DiagnosticChain diagnostics, Map<Object, Object> context)<br>
{<br>
if (!validate_NoCircularContainment(eClass, diagnostics,
context)) return false;<br>
boolean result = validate_EveryMultiplicityConforms(eClass,
diagnostics, context);<br>
if (result || diagnostics != null) result &=
validate_EveryDataValueConforms(eClass, diagnostics, context);<br>
if (result || diagnostics != null) result &=
validate_EveryReferenceIsContained(eClass, diagnostics,
context);<br>
if (result || diagnostics != null) result &=
validate_EveryBidirectionalReferenceIsPaired(eClass,
diagnostics, context);<br>
if (result || diagnostics != null) result &=
validate_EveryProxyResolves(eClass, diagnostics, context);<br>
if (result || diagnostics != null) result &=
validate_UniqueID(eClass, diagnostics, context);<br>
if (result || diagnostics != null) result &=
validate_EveryKeyUnique(eClass, diagnostics, context);<br>
if (result || diagnostics != null) result &=
validate_EveryMapEntryUnique(eClass, diagnostics, context);<br>
if (result || diagnostics != null) result &=
validateENamedElement_WellFormedName(eClass, diagnostics,
context);<br>
if (result || diagnostics != null) result &=
validateEClassifier_WellFormedInstanceTypeName(eClass,
diagnostics, context);<br>
if (result || diagnostics != null) result &=
validateEClassifier_UniqueTypeParameterNames(eClass,
diagnostics, context);<br>
if (result || diagnostics != null) result &=
validateEClass_InterfaceIsAbstract(eClass, diagnostics,
context);<br>
if (result || diagnostics != null) result &=
validateEClass_AtMostOneID(eClass, diagnostics, context);<br>
if (result || diagnostics != null) result &=
validateEClass_UniqueFeatureNames(eClass, diagnostics, context);<br>
if (result || diagnostics != null) result &=
validateEClass_UniqueOperationSignatures(eClass, diagnostics,
context);<br>
if (result || diagnostics != null) result &=
validateEClass_NoCircularSuperTypes(eClass, diagnostics,
context);<br>
if (result || diagnostics != null) result &=
validateEClass_WellFormedMapEntryClass(eClass, diagnostics,
context);<br>
if (result || diagnostics != null) result &=
validateEClass_ConsistentSuperTypes(eClass, diagnostics,
context);<br>
if (result || diagnostics != null) result &=
validateEClass_DisjointFeatureAndOperationSignatures(eClass,
diagnostics, context);<br>
return result;<br>
}</small><br>
</blockquote>
I.e., if diagnostics is null, then only the boolean result in
interesting, so as soon as it's false, no more constraints are
checked. But if the client wants diagnostics (too), not just a
boolean result, then all the constraints are checked and all the
reasons for being invalid are collected...<br>
<br>
<br>
On 03/04/2012 8:53 AM, Antonio Garcia-Dominguez wrote:
<blockquote cite="mid:jlf6e8$q7$1@xxxxxxxxe.org" type="cite">Hi
again,
<br>
<br>
I don't think that the short-circuit logic is wrong here. A model
element is not valid as soon as it doesn't meet some constraint,
so we shouldn't keep on evaluating the rest. The bug here is in
the EvlValidator class itself: it shouldn't produce a
NullPointerException in that case.
<br>
<br>
I've just committed a fix for EvlValidator that ensures that no
NPEs will be produced if validate(...) has not been called before.
Could you try it out?
<br>
<br>
Cheers,
<br>
Antonio
<br>
</blockquote>
</body>
</html>
|
|
| |
Re: Bug in org.eclipse.epsilon.evl.emf.validation [message #835844 is a reply to message #835793] |
Tue, 03 April 2012 14:47   |
Eclipse User |
|
|
|
Andrey,
Yes, that's the basis for my comment about, in the case that diagnostics
are being collected, being sure to collect them all. It would be
annoying to fix a problem, only to have another one show up, and doing
that several times. Better to know about all the problem; after all,
one might cause another...
On 03/04/2012 10:22 AM, Andrey Skorikov wrote:
> Hi Antonio,
>
> thank you for the fix! I checked out the new version and the NPE is
> gone. However, I still think that skipping the remaining validators in
> case one of them fails is not the right thing to do. We want to see
> the results of running all the validators, such that fixing all the
> warnings/errors in the model should result in a completely valid model.
>
> Cheers,
> Andrey
|
|
| | | |
Goto Forum:
Current Time: Wed Jul 23 07:20:25 EDT 2025
Powered by FUDForum. Page generated in 0.11181 seconds
|