Skip to main content

Safe Expressions

TeaQL E expressions provide safe value access across nested object graphs. They are designed to reduce null-check noise and avoid fragile nested getter chains.

The Problem

Plain Java access can become noisy when a value is several relations away:

if (item != null
&& item.getCustomOrder() != null
&& item.getCustomOrder().getCustomer() != null
&& item.getCustomOrder().getCustomer().getContactName() != null) {
// your logic
}

The code is defensive, but it hides the value being read.

Safe Null Check

if (E.customerOrderItem(item)
.getCustomOrder()
.getCustomer()
.getContactName()
.isNull()) {
// your logic
}

The expression keeps the property path readable while avoiding direct nested null access.

Safe Value Evaluation

String contactName = E.customerOrderItem(item)
.getCustomOrder()
.getCustomer()
.getContactName()
.eval();

Use eval() when you need the current value.

Empty Callback

E.customerOrderItem(item)
.getCustomOrder()
.getCustomer()
.getContactName()
.whenIsEmpty(() -> {
// do something
});

This is useful for business checks, fallback behavior, or response shaping.

Enum-style Helpers

Generated helpers can also make enum-style checks readable:

E.user(user)
.getGender()
.whenUserGenderIsFemale(() -> {
// do something
});

When to Use E

Use E when:

  • the value path crosses multiple relations;
  • optional data is expected;
  • the logic should stay readable;
  • null checks would distract from business intent.

Use ordinary getters when the object is local, required, and simple.