Skip to content

PatternMatchingInstanceof leaves unnecessary parentheses #4996

Closed
@PhilippWendler

Description

@PhilippWendler

Since ab45284 the PatternMatchingInstanceof check leaves parentheses that are flagged by the UnnecessaryParentheses check. I guess it is not desired that one Error Prone check produces code that another check than complains about?

One particular important case is:

if (o instanceof Test) {
  Test t = ((Test) o);
}

The parentheses make Error Prone miss the fact that it can eliminate the variable declaration and directly use o instanceof Test t.

Other cases found inside our code case and flagged by UnnecessaryParentheses are in return statements, inside divisions, and ternary operators. It is easy to extend PatternMatchingInstanceof.requiresParentheses() and fix particular cases, and I could do so in a PR, but I wonder whether this is the best approach, or whether the function should instead use a list of cases with required parentheses? So I wanted to clarify this upfront.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions