From: Lew on
teser3 wrote:
>>>     request.setAttribute("city", city);
>>>     try {
>>>         if(city.equals("Boston"))
>

Lew wrote:
>> Why not add a guard against 'null' here?
>

Jukka Lahtinen wrote:
> And the most compact way to do it would be just to turn the condition
> around to
>      if ("Boston".equals(city))
>

That's not a guard against 'null', that's a secret entrance for
'null'!

> Admitted, this may seem a little bit less intuitive than
>      if (city!=null && city.equals("Boston"))
> but it is shorter, and there's one comparison less.
>

Of course, doing that obscures the fact that a 'null' value was
received, which from the OP's surprise violates a desired invariant.

Explicit checks for 'null' are better than that silly hackish idiom.

Prevention of 'null' to make 'city != null' an invariant (i.e.,
assertable) is best.

--
Lew