I'm trying to read two csv's into my SQL Server. Getting NullPointerException
even though I'm allowing nullables and checking null each time. When debugging, it appears that the null check expression is evaluating to the FALSE condition every time, even when the string is null.
Here's an example of my null check:
( row2.Acq_date.equals(null) || row2.Acq_date.equals("") ||
row2.Acq_date == null ) ? null : (int)
TalendDate.diffDate(TalendDate.getCurrentDate(),row2.Acq_date,"MM")
You shouldn't do null checking like this row2.Acq_date.equals(null)
.
This is the correct way : row2.Acq_date == null
(which you actually included in your test, only doing it after testing row2.Acq_date.equals(null)
is too late, since that is the part throwing the NullPointerException
).
Here's the correct way :
( row2.Acq_date == null ? null : (int)
TalendDate.diffDate(TalendDate.getCurrentDate(),row2.Acq_date,"MM")
Based on your comment, row2.Acq_date
is of type date, which you can read directly from your file using the appropriate date format. If the column is empty (or contains whitespaces) in your file, Talend returns a null date, which is handled by the above test.