Search code examples
talend

Cannot invoke "String.replaceAll(String, String)" because row is null


I am getting an error message in Talend and it appears to be down to a having a 'NULL' value within my 'comments' field.

I currently have this expression row1.comments.replaceAll("\u0000", "") which has been working and the reason for having this in place is because I have some text which is spaced out (example T E S T).

However,the latest run has failed due to a 'NULL' appearing in the comments field and I don't think my job design knows how to handle this, as well as the removing the spaces from the 'comments' text.

This is the error message: Exception in component tMap_1 (FACT_test)

java.lang.NullPointerException: Cannot invoke "String.replaceAll(String, String)" because "row1.comments" is null

Is there anyway to get around this problem, please?


Solution

  • There's a little bit of information missing from your question (like what component are you using?) but regardless, you can check for null and deal with it accordingly using a ternary operator, something like this should work ...

    row1.comments == null ? "" : row1.comments.replaceAll("\u0000", "")