🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators isNull
This page was created by Hans.karlsen on 2017-11-20. Last edited by Wikiadmin on 2026-07-29.

You use isNull in OCL expressions to test whether a value has no assigned value.

Syntax

expression.isNull

The operator returns a Boolean value:

Expression result isNull returns
The expression has no assigned value true
The expression has an assigned value false

Example

Assume that vCar is a variable holding a Car object and that Name is an attribute of Car.

vCar.Name.isNull

This expression returns true when Name has not been assigned. It returns false when Name contains a value.

You can use the result in a condition. For example, this condition identifies a car whose name is not assigned:

if vCar.Name.isNull then
  -- Handle the missing name
endif

Test for null; do not compare with nullValue

Use isNull to test whether an expression is null. Do not compare an expression directly with <Type>.nullValue.

-- Correct: tests whether Name is null
vCar.Name.isNull

-- Wrong: do not use nullValue for a comparison
vCar.Name = String.nullValue

nullValue is a typed null value for assigning null to an attribute or variable, or for returning null from a method. It is not the null-test operator.

Related operators

Use isNull for a value that may be unassigned. Do not use collection operators to perform this test:

Need Use
Test whether a value is not assigned expression.isNull
Test whether a collection contains no elements isEmpty
Test whether a collection contains one or more elements notEmpty

See also