Class OptionalOfRedundantMethod

All Implemented Interfaces:
BugChecker.MethodInvocationTreeMatcher, Suppressible, Serializable

public class OptionalOfRedundantMethod extends BugChecker implements BugChecker.MethodInvocationTreeMatcher
Checks if Optional#of is chained with a redundant method.

Optional#of will always return a non-empty optional. Using any of the following methods:

  • isPresent
  • ifPresent
  • orElse
  • orElseGet
  • orElseThrow
  • or (only for Guava optionals)
  • orNull (only for Guava optionals)
on it is unnecessary and a potential source of bugs.
See Also: