Add null pointer checks in query validation.