General (#1) - includes(null) fails evaluation (#20) - Message List

includes(null) fails evaluation

Section 8.2 Types->VoidType of the OclSpec specifies 'null' can be owned by collections.

However the following expression fails : AnyClassYouLike.allInstances().aPropertyThatMayContainNull->includes(null))

The eclipse ocl interpreter returns true for this ocl expression, if a null value is contained within the collection

  • Message #49

    This sounds like a bug. May I ask in which context you need to evaluate such an expression?

    Have you also tried AnyClassYouLike.allInstances().aPropertyThatMayContainNull->includes(undefined)) ?

    • Message #50

      I'm evaluating an expression in a QVTOperational metamodel. QVTOperational defines a class MappingOperation which is inherited from ImperativeOperation. ImperativeOperation itself has a Property named _context. In QVTOperational there exist helpers which are inherited by ImperativeOperation, too. Their context may be null. So if I want to evalute i.e.


      This evaluation fails, because _context is null. Therefore I need to check, if _context is null.

      I tried to trace the bug but couldn't figure out what should be there. A NullPointerException is raised here: !QCLEvaluatorVisitorImpl->visit(PropertyCallExp host, Object data) at line 931 if (prop.getType() instanceof CollectionType)

      The property itself is null. Hope this helps.

      I also tried you suggestion which fails evaluation, too.

    • Message #59

      I tried you suggestion of using undefined in a different query:

      ImperativeOperation.allInstances()->select(name | not(name = undefined))

      This results in creation of a UndefinedLiteralExp? where as using 'null' I see a PathNameExp?.

      However evaluation of this query succeeds but results in an empty set which should not be empty.

      • Message #60

        You should try the following:

        ImperativeOperation.allInstances()->select(name | not name.oclIsUndefined())
        • Message #61

          This does evaluate to all instances including those with a null value. I furthermore figured that I get a NullPointerException? at the same place as mentioned above, if I remove the leading variable name and use this expression instead:

          ImperativeOperation.allInstances()->select(not name.oclIsUndefined())
          • Message #62

            Ok. I finally found a way to circumvent this: The query from message 60 is wrong as it picks each ImperativeOperation? as name instead of accessing ImperativeOperation?.name .

            However explicitly naming the variable seems to avoid the mentioned problem:

            ImperativeOperation.allInstances()->select(x | not(x._context.oclIsUndefined()))

            This results in all the instances of ImperativeOperation? that do not have a 'null' within its context.

  • Message #69

    I found more problems that seem to be related to this issue: Note that MappingOperation? is a subclass of ImperativeOperation?.


    both evaluate to an empty set which it should not for the model used

    ImperativeOperation.allInstances()->select(x : MappingOperation | x.oclIsTypeOf(MappingOperation)))

    proceeds evaluation despite the fact, that the Set is not of type MappingOperation?. The Eclipse OCL Framework does not evaluate this because of a type mismatch.

    ImperativeOperation.allInstances()->select(x : ImperativeOperation | x.oclIsTypeOf(MappingOperation)))

    proceeds evaluation as it should


No attachments created.