Class ComparisonOutOfRange

java.lang.Object
com.google.errorprone.bugpatterns.BugChecker
com.google.errorprone.bugpatterns.ComparisonOutOfRange
All Implemented Interfaces:
BugChecker.BinaryTreeMatcher, Suppressible, Serializable

public class ComparisonOutOfRange
extends BugChecker
implements BugChecker.BinaryTreeMatcher
Author:
bill.pugh@gmail.com (Bill Pugh), eaftan@google.com (Eddie Aftandilian)

TODO(eaftan): Support other types of comparisons? Are there likely to be errors in those?

See Also:
Serialized Form
  • Constructor Details

    • ComparisonOutOfRange

      public ComparisonOutOfRange()
  • Method Details

    • matchBinary

      public Description matchBinary​(com.sun.source.tree.BinaryTree tree, VisitorState state)
      Specified by:
      matchBinary in interface BugChecker.BinaryTreeMatcher
    • describe

      public Description describe​(com.sun.source.tree.BinaryTree tree, VisitorState state)
      Suggested fixes are as follows. For the byte case, convert the literal to its byte representation. For example, "255" becomes "-1. For the character case, replace the comparison with "true"/"false" since it's not clear what was intended and that is semantically equivalent.

      TODO(eaftan): Suggested fixes don't handle side-effecting expressions, such as (d = reader.read()) == -1. Maybe add special case handling for assignments.