If type1 is null (which is checked for earlier), this line will dereference it. Also, I'm not sure what the CONCAT operator is, but is it possible that the OR at the beginning of the same line should be an AND? Just checking...