Skip to main content

EL Expression

Check for Empty List (EL-001)

In order to check for empty list, use notEmpty() or isEmpty() but you do not need to check for null, those methods are handling those scenarios.

// Good
myList = null
isEmpty(myList) // This is true
notEmpty(myList) // This is false

myList = []
isEmpty(myList) // This is true
notEmpty(myList) // This is false

myList = [1, 2, 3]
isEmpty(myList) // This is true
notEmpty(myList) // This is false

// Bad
isEmpty(myList) || size(myList) == 0
notEmpty(myList) || size(myList) > 0
myList != null && notEmpty(myList)

The size() method could be also used to check if a list is empty, but this is also bad practice and should be avoided:

// Good
notEmpty(myList)
isEmpty(myList)

// Bad
size(myList) > 0
size(myList) == 0

Check for Boolean (EL-002)

This is similar to list, you do not need to check for null when checking for true / false

// Good
myBoolean = null
myBoolean // This is false
!myBoolean // This is true

myBoolean = true
myBoolean // This is true
!myBoolean // This is false

// Bad
myBoolean != null && myBoolean
myBoolean == true
myBoolean != false

Check for Integer (EL-003)

// Good
myObject.myInt > 0

// Bad / Not necessary
notEmpty(myObject) && myObject.myInt > 0

Check for Sub-Entitity Properties (EL-004)

// Good
notEmpty(myObject.object1.object2)

// Bad / Not necessary
notEmpty(myObject) && notEmpty(myObject.object1) && notEmpty(myObject.object1.object2)