Be careful with this. Sometimes unless you have created the DAO yourself then I would not trust this specialtyUserRole to not come back as null. Try CollectionUtils.isNotEmpty which will check for null and empty collections in one statement.