Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
NicolasTT
Contributor
Contributor

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:
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,
Labels (3)
7 Replies
Anonymous
Not applicable

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
NicolasTT
Contributor
Contributor
Author

My expression is :
!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;
Anonymous
Not applicable

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.
if(input_row.isOk==null)
output_row.isOk = 0;

Regards,
Pedro
NicolasTT
Contributor
Contributor
Author

Thanks,
But I'd like to keep my 'null' value. I don't want to set '0' if it's 'null'.
NicolasTT
Contributor
Contributor
Author

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?
Ravivarma_india
Contributor
Contributor

Initial stage of talend every one face a Null pointer exception ​, for TALEND TECH SUPPORT JION https://t.me/talendtechsupport

gjeremy1617088143
Master
Master

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