Skip to content

Commit

Permalink
Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 authored and rickie committed Jul 24, 2023
1 parent 1882d0c commit 50030d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@
import com.sun.source.tree.MethodInvocationTree;

/**
* A {@link BugChecker} that flags usages of Mongo {@code $text} filters used for full text
* searches.
* A {@link BugChecker} that flags usages of MongoDB {@code $text} filter usages.
*
* @see <a href="https://www.mongodb.com/docs/manual/text-search/">Mongo Text Search</a>
* @see <a href="https://www.mongodb.com/docs/manual/text-search/">MongoDB Text Search</a>
*/
@AutoService(BugChecker.class)
@BugPattern(
summary = "Avoid the `$text` operator in Mongo's full-text search queries",
link = BUG_PATTERNS_BASE_URL + "MongoFullTextSearchQueryUsage",
summary =
"Avoid MongoDB's `$text` filter operator, as it can trigger heavy queries and even cause the server to run out of memory",
link = BUG_PATTERNS_BASE_URL + "MongoDBTextFilterUsage",
linkType = CUSTOM,
severity = SUGGESTION,
tags = PERFORMANCE)
public final class MongoFullTextSearchQueryUsage extends BugChecker
public final class MongoDBTextFilterUsage extends BugChecker
implements MethodInvocationTreeMatcher {
private static final long serialVersionUID = 1L;
private static final Matcher<ExpressionTree> MONGO_FILTERS_TEXT_METHOD =
staticMethod().onClass("com.mongodb.client.model.Filters").named("text");

/** Instantiates a new {@link MongoFullTextSearchQueryUsage} instance. */
public MongoFullTextSearchQueryUsage() {}
/** Instantiates a new {@link MongoDBTextFilterUsage} instance. */
public MongoDBTextFilterUsage() {}

@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.google.errorprone.CompilationTestHelper;
import org.junit.jupiter.api.Test;

final class MongoFullTextSearchQueryUsageTest {
final class MongoDBTextFilterUsageTest {
@Test
void identification() {
CompilationTestHelper.newInstance(MongoFullTextSearchQueryUsage.class, getClass())
CompilationTestHelper.newInstance(MongoDBTextFilterUsage.class, getClass())
.addSourceLines(
"A.java",
"import com.mongodb.client.model.Filters;",
Expand All @@ -19,8 +19,6 @@ void identification() {
" Filters.text(\"foo\");",
" // BUG: Diagnostic contains:",
" Filters.text(\"foo\", new TextSearchOptions());",
" // BUG: Diagnostic contains:",
" Filters.text(\"foo\", new TextSearchOptions().caseSensitive(true));",
" }",
"}")
.doTest();
Expand Down
8 changes: 3 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,9 @@
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
<version>4.9.1</version>
<!-- XXX: Drop this when we forgo enforcement of
JDK 11 bytecode version compatibility. See follow-ups from:
https://github.com/PicnicSupermarket/error-prone-support/pull/603
https://github.com/PicnicSupermarket/error-prone-support/pull/198. -->
<version>4.10.2</version>
<!-- XXX: Drop this exclusion once we forgo enforcement of JDK
11 bytecode version compatibility. -->
<exclusions>
<exclusion>
<groupId>org.mongodb</groupId>
Expand Down

0 comments on commit 50030d8

Please sign in to comment.