Skip to content

Commit

Permalink
Automated rollback of commit 34d98e8.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

New behavior in ERROR-level check needs to be fixed across the depot.

This change, if deployed in a JavaBuilder release, would break many targets ([]

I've confirmed that this rollback fixes at least some of the errors in the
Javabuilder TGP, such as http://sponge2/56c76904-1bce-4ff3-9901-417f257c75ab.

*** Original change description ***

Remove conditional flags now that they are enabled.

#checkreturnvalue

***

PiperOrigin-RevId: 405950518
  • Loading branch information
amalloy authored and Error Prone Team committed Oct 27, 2021
1 parent f91fff5 commit 5538acc
Showing 1 changed file with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,20 @@ private static boolean functionalMethod(ExpressionTree tree, VisitorState state)
private static final Matcher<ExpressionTree> PRIMITIVE_METHODS =
allOf(not(PRIMITIVE_PARSING_METHODS), PRIMITIVE_NON_PARSING_METHODS);

/**
* The return values of {@link java.util.Optional} static methods and some instance methods should
* always be checked.
*/
private static final Matcher<ExpressionTree> OPTIONAL_METHODS =
anyOf(
staticMethod().onClass("java.util.Optional"),
instanceMethod().onExactClass("java.util.Optional").namedAnyOf("isEmpty", "isPresent"));

/**
* 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> OPTIONAL_METHODS =
private static final Matcher<ExpressionTree> MORE_OPTIONAL_METHODS =
anyMethod().onClass("java.util.Optional");

/**
Expand Down Expand Up @@ -347,39 +356,37 @@ private static boolean functionalMethod(ExpressionTree tree, VisitorState state)

private static final Matcher<? super ExpressionTree> SPECIALIZED_MATCHER =
anyOf(
// keep-sorted start
ARRAYS_METHODS,
CHAR_SEQUENCE_METHODS,
COLLECTION_METHODS,
COLLECTOR_METHODS,
ENUM_METHODS,
ITERABLE_METHODS,
ITERATOR_METHODS,
JODA_TIME_METHODS,
MAP_ENTRY_METHODS,
MAP_METHODS,
OBJECTS_METHODS,
OPTIONAL_METHODS,
PRIMITIVE_METHODS,
PROTO_METHODS,
RETURNS_SAME_TYPE,
ReturnValueIgnored::functionalMethod,
ReturnValueIgnored::javaTimeTypes,
STREAM_METHODS,
STRING_METHODS,
THROWABLE_METHODS,
TIME_UNIT_METHODS
// keep-sorted end
);
PROTO_METHODS,
PRIMITIVE_METHODS,
ARRAYS_METHODS,
OPTIONAL_METHODS,
TIME_UNIT_METHODS,
ReturnValueIgnored::javaTimeTypes,
COLLECTION_METHODS,
MAP_METHODS,
MAP_ENTRY_METHODS,
ITERABLE_METHODS,
ITERATOR_METHODS,
JODA_TIME_METHODS);

private final Matcher<? super ExpressionTree> matcher;

public ReturnValueIgnored(ErrorProneFlags flags) {
this.matcher =
anyOf(
SPECIALIZED_MATCHER,
getMatcher(flags, "ReturnValueIgnored:MoreOptional", MORE_OPTIONAL_METHODS),
getMatcher(flags, "ReturnValueIgnored:ClassMethods", CLASS_METHODS),
getMatcher(flags, "ReturnValueIgnored:ObjectMethods", OBJECT_METHODS));
getMatcher(flags, "ReturnValueIgnored:ObjectMethods", OBJECT_METHODS),
getMatcher(flags, "ReturnValueIgnored:ObjectsMethods", OBJECTS_METHODS),
getMatcher(flags, "ReturnValueIgnored:CharSequenceMethods", CHAR_SEQUENCE_METHODS),
getMatcher(flags, "ReturnValueIgnored:EnumMethods", ENUM_METHODS),
getMatcher(flags, "ReturnValueIgnored:ThrowableMethods", THROWABLE_METHODS),
getMatcher(flags, "ReturnValueIgnored:CollectorMethods", COLLECTOR_METHODS));
}

private static Matcher<? super ExpressionTree> getMatcher(
Expand Down

0 comments on commit 5538acc

Please sign in to comment.