• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » java.lang.NullPointerException when setting a 'null' value

#1 2012-04-19 11:29:15

NicolasTT
Member
Registered: 2011-01-14
Posts: 34

java.lang.NullPointerException when setting a 'null' value

Tags: [bug, database, java]

Hello,

I am faced with a 'java.lang.NullPointerException' when I set a null value in a (nullable) field a table of my database.

Here's the scenario:
An external source (my tFixedFlowInput in my example) can have a value and then change the value in base, or have no value, and in this case, I set the previous value to the base.
This works, except in the case I have no value in either the external source, or in the database (null and null). In this case, I have a 'java.lang.NullPointerException' on the line corresponding to the value of the field in the TMap:

Code:

temp_nva_out_tmp.isOK = !Relational.ISNULL(IN.isOK) ? 1 : temp_nva_in.isOK;

I do not understand how the assignment of the null can generate
'java.lang.NullPointerException'. If I replace temp_nva_in.isOK by 'null', it works correctly.

Thanks for ideas,


Uploaded Images

Last edited by NicolasTT (2012-04-19 11:38:35)

Offline

#2 2012-04-19 11:41:32

pedro
Member
Registered: 2011-11-17
Posts: 3682

Re: java.lang.NullPointerException when setting a 'null' value

Hi

It's a rule that you can type null in expression. But if expression get null from a variable, it will cause NPE exception.

Regards,
Pedro


Only Paranoid Survive.

Offline

#3 2012-04-19 11:48:59

NicolasTT
Member
Registered: 2011-01-14
Posts: 34

Re: java.lang.NullPointerException when setting a 'null' value

My expression is :
!Relational.ISNULL(in.isOK) ? 1 : temp_nva_in.isOK
is the Tmap.

In the java code :

Code:

// # Output table : 'temp_nva_out'
    temp_nva_out_tmp.uid = in.uid;
    temp_nva_out_tmp.isOK = !Relational.ISNULL(in.isOK) ? 1 : temp_nva_in.isOK;
    temp_nva_out = temp_nva_out_tmp;

Offline

#4 2012-04-19 12:09:48

pedro
Member
Registered: 2011-11-17
Posts: 3682

Re: java.lang.NullPointerException when setting a 'null' value

Hi

It seems that there are null values in temp_nva_in.isOK.
You can put a tJavaRow between the input component and tMap and type code as follow.

Code:

if(input_row.isOk==null)
output_row.isOk = 0;

Regards,
Pedro


Only Paranoid Survive.

Offline

#5 2012-04-19 13:29:14

NicolasTT
Member
Registered: 2011-01-14
Posts: 34

Re: java.lang.NullPointerException when setting a 'null' value

Thanks,

But I'd like to keep my 'null' value. I don't want to set '0' if it's 'null'.

Offline

#6 2012-04-19 14:20:59

NicolasTT
Member
Registered: 2011-01-14
Posts: 34

Re: java.lang.NullPointerException when setting a 'null' value

Code:

temp_nva_out_tmp.isOK = !Relational.ISNULL(in.isOK) ? new Integer( 1 ) : temp_nva_in.isOK;

works and

Code:

temp_nva_out_tmp.isOK = !Relational.ISNULL(in.isOK) ? 1 : temp_nva_in.isOK;

doesn't work.

I don't understand why. Thanks if you could explain me?

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » java.lang.NullPointerException when setting a 'null' value

Board footer

Powered by FluxBB