Skip to content

Commit

Permalink
Match all Optional methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoenig10 committed Apr 20, 2021
1 parent 1cbf057 commit 6fec586
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,11 @@ private static boolean functionalMethod(ExpressionTree tree, VisitorState state)
"isPresent"));

/**
* The return values of {@link java.util.Optional} static methods and some instance methods should
* always be checked.
* The return values of {@link java.util.Optional} methods should always be checked (except for
* void-returning ones, which won't be checked by AbstractReturnValueIgnored).
*/
private static final Matcher<ExpressionTree> MORE_OPTIONAL_METHODS =
anyOf(
instanceMethod().onExactClass("java.util.Optional")
.namedAnyOf(
"filter",
"flatMap",
"get",
"map",
"or",
"orElse",
"orElseGet",
"orElseThrow"));
anyMethod().onClass("java.util.Optional");

/**
* The return values of {@link java.util.concurrent.TimeUnit} methods should always be checked.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public void optionalInstanceMethods() {
" optional.flatMap(v -> Optional.of(v + 1));",
" // BUG: Diagnostic contains: ReturnValueIgnored",
" optional.get();",
" optional.ifPresent(v -> {});",
" // BUG: Diagnostic contains: ReturnValueIgnored",
" optional.isPresent();",
" // BUG: Diagnostic contains: ReturnValueIgnored",
Expand Down

0 comments on commit 6fec586

Please sign in to comment.