[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.mdt.ocl] Expressions involving undefined values

Good day mdt.ocl,

Many of our OCL constraints involve complex chained expressions referencing 
modelled features and query operations, any part of which could be 
undefined.

According to "OCL 2.0 Specification  ptc/2005-06-06" Paragraph 7.4.11 (?) 
"Undefined Values":
"Some expressions will, when evaluated, have an undefined value. For 
instance, typecasting with oclAsType() to a type that the object does not 
support or getting the ->first() element of an empty collection will result 
in undefined. In general, an expression where one of the parts is undefined 
will itself be undefined..." However, in practice I see 
NullPointerExceptions when such expressions are evaluated. For example:

inv inParamControlDisabled: let opposite : Bindable = 
getInboundValueBinding()->first().getOppositeEndpoint(self).target in 
enabled.value and opposite.oclIsKindOf(Parameter) implies 
opposite.oclAsType(Parameter).inout <> InOutType::IN

throws NPE if getInboundValueBinding() returns an empty list, apparently as 
a result of attempting to using Java reflection APIs to invoke the 
getOppositeEndpoint() method on a null reference. At present the only way 
around this is to make the OCL expressions self-null-checking, which 
obviously makes them more complicated than the spec. suggests they need be, 
less readily comprehensible and (presumably) less performant.

Is my understanding of the OCL spec. flawed or is this a bug?

Thanks in advance,

Adrian Price
Senior Architect
TIBCO Software, Inc.