The parentheses are useless to the compiler because && takes precedence
over ||. The parentheses are useful to humans who have not memorized Java
operator precedence ;)

This warning is useful to catch weird style choices like "return (foo +
bar);" I've seen other odd choices in parentheses styling.

Gary


On Mon, May 13, 2013 at 11:09 AM, Nick Williams <
nicho...@nicholaswilliams.net> wrote:

> The PMD inspector says the following if statement contains "Useless
> parentheses."
>
>         if ((isEventTimestamp && isLiteralValue) || (isEventTimestamp &&
> isPattern) || (isLiteralValue && isPattern)) {
>             LOGGER.error("The pattern, literal, and isEventTimestamp
> attributes are mutually exclusive.");
>             return null;
>         }
>
> I'm all for removing useless parentheses; unfortunately, I don't see how
> these are useless. The way I see it, if isLiteralValue is false, with
> parentheses it will (correctly) continue to evaluate after the first
> grouped condition but without parentheses it would (incorrectly) short
> circuit after the first use of isLiteralValue.
>
> Am I missing something here? Or is this a PMD bug?
>
> Nick
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-dev-h...@logging.apache.org
>
>


-- 
E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Reply via email to