From 521b1b9ee9970e062fdbd78271afa3e461477c1c Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sun, 23 Jul 2023 13:01:51 +0200 Subject: [PATCH] Suggestions --- ...eryUsage.java => MongoDBTextFilterUsage.java} | 16 ++++++++-------- ...Test.java => MongoDBTextFilterUsageTest.java} | 6 ++---- pom.xml | 8 +++----- 3 files changed, 13 insertions(+), 17 deletions(-) rename error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/{MongoFullTextSearchQueryUsage.java => MongoDBTextFilterUsage.java} (76%) rename error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/{MongoFullTextSearchQueryUsageTest.java => MongoDBTextFilterUsageTest.java} (72%) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MongoFullTextSearchQueryUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MongoDBTextFilterUsage.java similarity index 76% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MongoFullTextSearchQueryUsage.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MongoDBTextFilterUsage.java index 60dbdab850..77208f673e 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MongoFullTextSearchQueryUsage.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MongoDBTextFilterUsage.java @@ -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 Mongo Text Search + * @see MongoDB Text Search */ @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 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) { diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MongoFullTextSearchQueryUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MongoDBTextFilterUsageTest.java similarity index 72% rename from error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MongoFullTextSearchQueryUsageTest.java rename to error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MongoDBTextFilterUsageTest.java index 2677c0dbb4..ea9ca288a8 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MongoFullTextSearchQueryUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MongoDBTextFilterUsageTest.java @@ -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;", @@ -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(); diff --git a/pom.xml b/pom.xml index dc38278d6a..265360736b 100644 --- a/pom.xml +++ b/pom.xml @@ -446,11 +446,9 @@ org.mongodb mongodb-driver-core - 4.9.1 - + 4.10.2 + org.mongodb