[resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

One Star

[resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

I discovered what the actual problem was and posted a screen shot. See my last post for details. I'd be happy to host a WebEx session if anyone is interested enough in that.





I have a job that combines 3 delimited input files into a single delimited output file. The program runs perfectly, no errors.
However I have to change one of my delimited input files (the main) to a different excel input file. I mapped it correctly, all the fields are nullable. When I run the job I get the following error:
Exception in component tMap_1
java.lang.NullPointerException
at testproject.pimco_0_2.PIMCO.tFileInputDelimited_2Process(PIMCO.java:24714)
at testproject.pimco_0_2.PIMCO.runJobInTOS(PIMCO.java:27633)
at testproject.pimco_0_2.PIMCO.main(PIMCO.java:27498)
I tried a new job where I have only the new excel file and I copied the tMap. When I run that job, it works fine. The nullpointer error only happens when I try to combine the new file with the two other delimited input lookup files.
I tried making different files the main file and the problem is always with the main, never the lookup files.
I forgot to mention that the excel file has no null values. I tried changing every cell to the same string value and I still got the same error. I also used Talend to convert the file from excel to a CSV so it would be the same filetype as the other two. Talend still gave me a null pointer error when I tried combining the three files, but when I only use the new file I get no error.
This is pretty urgent so any suggestions would be greatly appreciated.
Thanks a ton in advanced,
JJ Potgieter.

Accepted Solutions
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

It's because you're doing the replace before checking for null (I think). So you need to do the isnull and then replace if false.

All Replies
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

Here is my screen. Let me know if you need a different screenshot.
Four Stars

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

You may have already tried this - and this may not be your issue at all - but in case it is, it's always good practice to handle nulls before using fields...
row1.account_type != null && row1.account_type.length() > 0 : row1.account_type.equals("Parent")
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

You may have already tried this - and this may not be your issue at all - but in case it is, it's always good practice to handle nulls before using fields...
row1.account_type != null && row1.account_type.length() > 0 : row1.account_type.equals("Parent")

I will do so in the future, but I have a lot of fields and I'm fairly confident that this isn't the problem. The reason why I'm sure that it isn't the problem is because I changed every cell in the excel file to the same string value to make sure that none of the cells are null, but I still got the error.
Seventeen Stars

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

hi all,
are you using some filter in your Tmap or any java function like comparison or equality ?
null pointer is often the result for using a 'java function' that doesn't support null value.
As willm as mentionned, manage null value is a good way to avoid that.
Try to catch null value by using tschemaComplianceCheck and reject flow to catch those 'bad data'.
You also use the java debug run to find null value, but it's more a java expert solution.
hope it helps
regards
laurent
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

Something wrong with the first record in tFileInputDelimited2. Does it have a header which you didn't include?
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

Thanks for the suggestions kzone and janhess, but they're not the issue. The filter sounded really promising because I forgot that I had included one, but when I removed it nothing changed.
I did trouble shoot where the error is coming from. When the collateral lookup is linked to the new file's LoanNumber I get the error. It doesn't give me an error when the collateral lookup file is connected to the old Loan file, only the new Loan file. I'm not 100% sure what this means but at least I know where to look for my error.
I just confirmed that there are plenty of LoanNumbers that exist in both the collateral file and the Loan file, so I'm really lost as to what could be causing this error.
I went into tMap and deleted every field where I mapped the collateral fields to the output file, so only the Insurance and Loan data is there, and I still have the same error...
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

I seem to have found the cause of the problem, but I'm not sure how to fix it. When I use the Loan file's LoanNum as the expression key for the Collateral file, I get a null pointer error if one file has a LoanNum the other file doesn't have. I tried filtering it out on the output file and you can see my code in the screenshot. It seems like the filter code I used for the output only works a few times. It's currently getting the null exception error on line 681.
The reason for this error is that on line 682 there is a LoanNum in the Loan file that doesn't exist in the Collateral or Insurance file. The filter should exclude it though, shouldn't it?
I fixed the filter to Loan.LoanNum.equals(Collateral.LoanNum) as it should be, but it still gives me the null exception error on line 681
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

You shouldn't be using the filter in that way. That condition is handled by the join on the input. If you have an inner join it will not pass any unmatched Collateral records to the output.
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

You shouldn't be using the filter in that way. That condition is handled by the join on the input. If you have an inner join it will not pass any Collateral records to the output.

I see. Then how do I handle the nullpointerexception?
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

The NullPointer Exception comes from trying to do a function on a collateral field when there hasn't been a match. Check for null in the rule.
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

The NullPointer Exception comes from trying to do a function on a collateral field when there hasn't been a match. Check for null in the rule.

Where would I put the rule? I tried putting the code:
Collateral.FIELDNAME != null && Collateral.FIELDNAME.length() > 0 ? Collateral.FIELDNAME : null
on every field in the output where I mapped the collateral file to the output file and it didn't help.
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

For example in rule for escrow put
! Relational.ISNULL(
before existing rule and ) at end.
But if you use an inner join for input none of the fields will be null unless there's nulls in the data.
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

For example in rule for escrow put
! Relational.ISNULL(
before existing rule and ) at end.
But if you use an inner join for input none of the fields will be null unless there's nulls in the data.

When I tried that it gave me an error saying that it can't convert Boolean to String. I literally put the ! Relational.ISNULL() around my field, ie ! Relational.ISNULL(Collateral.ESCROW). I assume I'm supposed to use it as an if test expression, like:
! Relational.ISNULL(Collateral.ESCROW) ? Collateral.ESCROW : null
Is that correct?
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

Yes sorry. should be
! Relational.ISNULL(value)?rule true:rule false
It's difficult to see what's in your rules from the picture.
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

Yes sorry. should be
! Relational.ISNULL(value)?rule true:rule false
It's difficult to see what's in your rules from the picture.

I went ahead and added code to every Collateral field so it looks something like this:
! Relational.ISNULL(Collateral.PrimaryBorrowerName != null && Collateral.PrimaryBorrowerName.length() > 0 ? Collateral.PrimaryBorrowerName : null) ? Collateral.PrimaryBorrowerName != null && Collateral.PrimaryBorrowerName.length() > 0 ? Collateral.PrimaryBorrowerName : null :null
It compiles fine, but still gives me a nullpointerexception on line 1
Edit: I know the code is redundant with the null testing, but I just wanted to try it out as fast as possible.
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

Firstly the rule is wrong. All you need is
! Relational.ISNULL(Collateral.PrimaryBorrowerName)?Collateral.PrimaryBorrowerName?null.
but this isn't where the problem is as there's no function done on the data.
Look on your code tab for the line being flagged as the null pointer exception and it will tell you where the problem is.
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

Firstly the rule is wrong. All you need is
! Relational.ISNULL(Collateral.PrimaryBorrowerName)?Collateral.PrimaryBorrowerName?null.
but this isn't where the problem is as there's no function done on the data.
Look on your code tab for the line being flagged as the null pointer exception and it will tell you where the problem is.

I looked at the error and it pointed me to the MAILADDR2 field. Just to confirm your theory I deleted the Collateral input fields on every output where there was a function and it compiled and ran without errors so you're 100% correct, thank you so much. I've been trying to figure this out for a week and it was driving me crazy, but I was looking in the wrong place the whole time.
For the MAILADDR2 field, I originally tried to remove null values so the code is a mess. Currently it is written as:
Loan.MailAddr2 != null && Loan.MailAddr2.length() > 0 && Loan.MailState != null && Loan.MailState.length() > 0 && Loan.MailZip != null && Loan.MailZip.length() > 0 ? Loan.MailAddr2.replace("\"","").isEmpty() ? Loan.MailCity.replace("\"","") + " " + Loan.MailState.replace("\"","") + " " + Loan.MailZip.replace("\"","") : Loan.MailAddr2 : null
I'm assuming that the correct code would be:
!Relational.ISNULL(Loan.MailAddr2.replace("\"","").isEmpty() ? Loan.MailCity.replace("\"","") + " " + Loan.MailState.replace("\"","") + " " + Loan.MailZip.replace("\"",""))
? Loan.MailAddr2.replace("\"","").isEmpty() ? Loan.MailCity.replace("\"","") + " " + Loan.MailState.replace("\"","") + " " + Loan.MailZip.replace("\"","")
: null
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

You probably don't need the isEmpty check.
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

You probably don't need the isEmpty check.

I'm guessing that when I started this project I saw a nullpointerexception and assumed it was because a field was empty so I put a lot of unnecessary code in. Thanks a lot for the help. I'll try adding the Relational.ISNULL() code in soon and report back on whether or not it works.
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

I'm still getting the nullpointerexception. I've uploaded screenshots of the error that I'm getting, then a screenshot of the code at the line from the error message, then the field that gave me the code. Oh and I had to change the connection from Collateral to Loan, sorry if that caused any confusion.
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

It's because you're doing the replace before checking for null (I think). So you need to do the isnull and then replace if false.
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

It's because you're doing the replace before checking for null (I think). So you need to do the isnull and then replace if false.

WOW! Never in a million years would I have suspected that this was the problem. It is now working as intended, thank you so much!
If you're even in the Atlanta area I'll have to to buy you a lunch Smiley Wink
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

Hi,
I have a situation, I have source table and from that i am spliting data into 2 table on the basis of some validation on columns.
validation :  Suppose i have Name column and its length is 10 but in some cases i found that Name column has values more than the length(10) . so in this case i want to split data in to 2 tables .
if values are greater than length then it goes to ERROR table and value is equal or less than length then it goes to proper Target table.
&
I have done with given situation with this logic row1.TRINAMETX.length()>10 
But,
I am getting error....
Starting job Job_Geography_triCountry_Part_1 at 15:03 11/09/2015.
connecting to socket on port 4008
connected
Exception in component tMap_1
java.lang.NullPointerException
at demo.job_geography_tricountry_part_1_0_1.Job_Geography_triCountry_Part_1.tFileInputExcel_1Process(Job_Geography_triCountry_Part_1.java:3648)
at demo.job_geography_tricountry_part_1_0_1.Job_Geography_triCountry_Part_1.runJobInTOS(Job_Geography_triCountry_Part_1.java:6206)
at demo.job_geography_tricountry_part_1_0_1.Job_Geography_triCountry_Part_1.main(Job_Geography_triCountry_Part_1.java:6065)
disconnected
Job Job_Geography_triCountry_Part_1 ended at 15:03 11/09/2015.

Waiting for the Reply?
Thanks in Advance.
Regards,
Shriram
Talend User.
One Star

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

no one replied to my post....feeling very bad Smiley Sad
Community Manager

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

Hi Shri_kul1
Sorry for the delay reply. About the NPE, there exists null value in the TRINAMETX column, you need to check the NULL value, filter the null value or transform it to other value, for example, replace null value with empty string:
row1.TRINAMETX==null? "":row1.TRINAMETX
before you handle it with the logic row1.TRINAMETX.length()>10.

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Seventeen Stars

Re: [resolved] NullPointerException (possible bug) in tMap [Need Help With a Filter]

hi,
as you said , same situation : you 've to manage null value
you try row1.TRINAMETX.length when row1.TRINAMETX is null
=> java try to manage null.length() ... but it couldn't.
so in your code do something like :

row1.TRINAMETX != null ?
row1.TRINAMETX.length()>10 :
/* your code here when row1.TRINAMETX is null */


regards
laurent
Ps : didn't seen Shong's answer (on page 2  ... Smiley Happy )
apologize @Shong Smiley Wink