1

I am having a bit of troubles trying to understand the semantics of OCL operands in the OCL specification of version 2.4. In particular, to begin with, given a contextual model as a Student class, in which the available attributes is his age, then consider the current instance of this model includes the assignment of variable object is a student whose age is undefined. I would like to ask what would the return value be when evaluating these the following examples:

  • object.age = 18
  • object.age = object.age
  • object.age >= 18
  • object.age >= object.age

Basically, I would like to understand the semantics of these operands in the presence of an undefined value.

Thanks everyone!

HoaNg
  • 25
  • 2

1 Answers1

1

There is no such concept as undefined in OCL 2.x. The vague OCL 1.x undefined concept evolved to null (not initialized) and invalid (bad).

In all your cases, use of the invalid value is not computable and so the result is invalid. In simple terms, a crash crashes.

Use of a null value compares to (another) null as true, but as false otherwise. In simple terms null is just another value that compares for equality as you might expect.

Relative comparisons of null are of course invalid.

The relevant OCL 2.4. specification sections are 11.2.4 and 11.3.2.

If you really want to understand how OCL handles computation failures, you may find [1] helpful .

[1] http://www.eclipse.org/modeling/mdt/ocl/docs/publications/OCL2021Validity/OCLValidity.pdf

Ed Willink
  • 1,205
  • 7
  • 8
  • Hi Ed, thanks for your answer. I now understand that OCL supports a four-valued logic, including the newly null and invalid. Invalid represents 'error', so when it appears at in the subexpression, it propagates its invalid-ness to the top: that makes sense. About the null, I have always imagined that its semantics is somehow identical to the SQL, in which, I believe, SELECT NULL = NULL returns NULL. Of course, OCL is not SQL so the semantics can be different. I just want to ask whether you have any idea about the rationale behind the semantics of "=" between two null value returning true? – HoaNg Mar 05 '22 at 19:37
  • The attached paper seems interesting, perhaps I could find the answer to my question in there as well. Thanks also for the pointer. – HoaNg Mar 05 '22 at 19:38
  • *null* is a well-behaved value in so far as an error free model may contain null values,. If one *null* was not equal to another that would be very odd. In practice OCL implementations are based on Java and so it is instructive to see how Java handles similar scenarios. That doesn't mean that OCL must do the same as Java, but there should be a good reason to be different. In Java null is equal to null. – Ed Willink Mar 05 '22 at 20:13