
Contributor
2012-04-19
06:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
java.lang.NullPointerException when setting a 'null' value
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:
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,
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:
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,
1,381 Views
7 Replies

Anonymous
Not applicable
2012-04-19
06:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
1,381 Views

Contributor
2012-04-19
06:48 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My expression is :
!Relational.ISNULL(in.isOK) ? 1 : temp_nva_in.isOK
is the Tmap.
In the java code :
!Relational.ISNULL(in.isOK) ? 1 : temp_nva_in.isOK
is the Tmap.
In the java 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;
1,381 Views

Anonymous
Not applicable
2012-04-19
07:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Regards,
Pedro
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.
if(input_row.isOk==null)
output_row.isOk = 0;
Regards,
Pedro
1,381 Views

Contributor
2012-04-19
08:29 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks,
But I'd like to keep my 'null' value. I don't want to set '0' if it's 'null'.
But I'd like to keep my 'null' value. I don't want to set '0' if it's 'null'.
1,381 Views

Contributor
2012-04-19
09:20 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
temp_nva_out_tmp.isOK = !Relational.ISNULL(in.isOK) ? new Integer( 1 ) : temp_nva_in.isOK;
works and
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?
1,381 Views

Contributor
2021-06-28
10:32 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Initial stage of talend every one face a Null pointer exception , for TALEND TECH SUPPORT JION https://t.me/talendtechsupport
1,381 Views

Master
2021-06-29
03:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, it's due to ternary autoboxing, in the first one it reads the left part as an Integer (it's a wrapper Object wich accept null value) so it will convert temp_nva_in.isOK to Integer
in the second one you set 1 on the left it will read it as an int and convert it as an int(doesn't support null values it's a primitive type) so it throw null pointer exception if temp_nva_in.isOK is null.
you could also write :
temp_nva_out_tmp.isOK = in.isOK != null? new Integer( 1 ) : temp_nva_in.isOK;
Send me Love and Kudos
1,381 Views
