I think you want
if (l == invalid || r == invalid ) invalid else {...other stuff }