---
schema_version: "1"
id: d47a328adcba25cb98c15193f2083c6c9f79ba5100b83c31eb7a85018e860c21
title: Null Safe
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-sdk/latest/null-safe.md
canonical_url: https://docs.mulesoft.com/mule-sdk/latest/null-safe
source_site: docs.mulesoft.com
content_type: documentation
content_hash: c31728dcb1509c003343245ff89860caad1054a09cb811eaa13a2ff0f3f4e806
description: MuleSoft Documentation Site
release: "1.13"
latest: true
---
---
product: Mule SDK
version: 1.13
is-latest-version: true
keywords: mule, sdk, annotations, null, safe
---

# Null Safe

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

In some cases, you might want to instantiate a `@Parameter` even though the end user has not
provided a value, for example:

```java
@Parameter
@Optional
private List<Integer> numbers;
```

While interacting with `numbers` in your code, you will need to check if `numbers == null` at some
point to avoid a `NullPointerException`.

The SDK supports the use of annotations like `@NullSafe`, which can provide an empty list instead of
`null`. When you use it, the SDK can automatically create a value for you if the value was not
configured.

There are many "flavors" of `@NullSafe` annotations. When used with `List` and `Map` interfaces,
`@NullSafe` will provide a default implementation for those collections.

This example shows a POJO as a null safe type:

```java
@Parameter
@Optional
@NullSafe
private Foo foo;
```

As you might expect, the SDK will instantiate `Foo` and assign it to your `foo` parameter so that
you do not have to manually check for null.

Note that if you use `@NullSafe` with a POJO, all the parameters declared inside the POJO must all
be _optional_. If a parameter is required, there is no default value for the SDK to use. So, using
`@NullSafe` to automatically instantiate required parameters makes no sense.

`@NullSafe` can be configured to instantiate a certain class instead of using the parameter’s type.
This can be helpful in the cases where the parameter’s type cannot be instantiated (like an abstract
class or an interface).

You specify the class to be instantiated by setting the `defaultImplementingType` attribute in the
annotation, for example:

```java
@Parameter
@Optional
@NullSafe(defaultImplementingType = Foo.class)
private AbstractFoo foo;
```
