One Star

NullPointerException issue when using 'conditional if' in tMap

Hi All,
I am using a conditional if statement in tMap component. This is the screenshot of my job.

The first row of the Excel file has an empty value in the OLD_DATA_SIZE column.
The type of var2 is Integer and the job throws a NullPointer Exception. But, once I change the type to String and convert the var2 explicitly into Interger in the row 's' , it works fine.
As I figured out the 'null' value which is at the end of the following expression creates the issue.
!StringUtils.getSize(row3.OLD_DATA_TYPE).equals("") ? Integer.parseInt(StringUtils.getSize(row3.OLD_DATA_TYPE)) : (row3.OLD_DATA_SIZE != null ? row3.OLD_DATA_SIZE : null)      
Does anyone knows the reason behind this?

Seventeen Stars

Re: NullPointerException issue when using 'conditional if' in tMap

I guess the data type of the OLD_DATA_TYPE is Integer - your tMap expression looks like this.
In this case you have made a very cumbersome way, please try this:
row3.OLD_DATA_TYPE != null ? row3.OLD_DATA_TYPE : 0

The problem in your job is the output column is probably not nullable -> use as data type int instead of Integer 
Java converts automatically an so called wrapper type like Integer into the primitive data type int with an unboxing. The unboxing is nothing else then the call to the method intValue to the incoming Integer typed value. If the incoming value is null this implicit method call (which cannot be seen as readable code in your job) causes the NullPointerException.
Thats because I have used as null replacement value the zero.
One Star

Re: NullPointerException issue when using 'conditional if' in tMap

Thanks for the reply jlolling.
Data type of the OLD_DATA_TYPE is Integer and it is Nullable. And in the database it is mapped to a column which is NUMBER and nullable.
Since OLD_DATA_TYPE is nullable we should be able to null I guess.
Later I tried making the data type of the Var.var2 and as String and did the relevant conversions(String --> Integer). 
Then it worked. But still I cannot figure out what happens when it comes to Integer (nullable).