In an IvyScriptStep variables are auto initialized as soon as they are accessed. The following code will log "bad":

java.util.Date date = null;
if ( date!=null) {"bad");
} else {"good");

It looks like the object "date" will never be a java.util.Date, it is an IvyDate. There is also no chance to import java.util.Date because of a conflict.

asked 06.11.2013 at 14:42

Adrian%20Imfeld's gravatar image

Adrian Imfeld
accept rate: 77%

edited 07.11.2013 at 12:12

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦

A simple solution is to transfer the code to a handler class and call the methode from the IvyScript-Step.

If you still want the code in a ScriptStep, you could do the following:

import java.util.concurrent.atomic.AtomicReference;
AtomicReference date = new AtomicReference();
//date.set(new java.util.Date());
if ( date.get()!=null) {"bad");
} else {"good");

answered 06.11.2013 at 14:45

Adrian%20Imfeld's gravatar image

Adrian Imfeld
accept rate: 77%

edited 06.11.2013 at 14:49

IvyScript auto initialise default types like:

  • Strings with an empty String
  • Numbers with zero
  • java.util.Date with a default value of '0001-01-01 00:00:00'

To handle this inside IvyScript the is initialized statement is the recommended operator to check if a variable is null or was auto initialized. Example:

Date myDate =;
if (myDate is initialized) {"myDate is not the default value");    
} else {
    ivy.log.error("myDate is auto initialized");    

As long as we are working inside IvyScript anything works fine. When we want to use the variable as a parameter, e.g. to call a method in Java, we have to pay attention to the auto initialization. Example:

// getMyDate() returns null
Date myDate =;

// below line prints: 'Sat Jan 01 00:00:00 CET 1', 
// because is was auto initialized even getMyDate() returns null

// below line prints: 'null', becaue we pass null if the variable was auto initialized
MyJavaClass.printDate(myDate is initialized ? myDate : null);

If we navigating through beans we could also use the #-operator. This operator prevents auto initialization. Example:

if ( == null)
   // yes, the field 'adressBean' is null and was not auto initialized

When we working with types which could not be initialized (like interfaces), we have to use the #-operator too. Example:

IInterfaceX interfaceX =;
if (#interfaceX != null)
   // call a method on the interface.

// below call will fail with an exception, because IvyScript could not auto initialized an interface

See also the chapter IvyScript & Null Handling for more details.

This answer is marked "community wiki".

answered 08.11.2013 at 15:43

Flavio%20Sadeghi's gravatar image

Flavio Sadeghi ♦♦
accept rate: 75%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 06.11.2013 at 14:42

Seen: 4,037 times

Last updated: 08.11.2013 at 15:43