diff --git a/packages/jetbrains-plugin/src/main/kotlin/com/mongodb/jbplugin/observability/probe/InspectionStatusChangedProbe.kt b/packages/jetbrains-plugin/src/main/kotlin/com/mongodb/jbplugin/observability/probe/InspectionStatusChangedProbe.kt index 31c98246..b71563b7 100644 --- a/packages/jetbrains-plugin/src/main/kotlin/com/mongodb/jbplugin/observability/probe/InspectionStatusChangedProbe.kt +++ b/packages/jetbrains-plugin/src/main/kotlin/com/mongodb/jbplugin/observability/probe/InspectionStatusChangedProbe.kt @@ -20,6 +20,7 @@ import kotlinx.coroutines.launch import java.lang.ref.WeakReference import java.util.Collections import java.util.UUID +import java.util.concurrent.CopyOnWriteArrayList private val inspectionTelemetry = Dispatchers.IO private val logger: Logger = logger() @@ -47,7 +48,7 @@ class InspectionStatusChangedProbe( val elementsWithProblems = problemsByInspectionType(inspectionType) // check if the element is already in the list - if (isElementRegistered(elementsWithProblems, psiElement)) { + if (isElementRegistered(elementsWithProblems) { psiElement }) { // do nothing, it's already registered return@launch } @@ -85,7 +86,7 @@ class InspectionStatusChangedProbe( cs.launch(inspectionTelemetry) { val elementsWithProblems = problemsByInspectionType(inspectionType) - if (isElementRegistered(elementsWithProblems, psiElement)) { + if (isElementRegistered(elementsWithProblems) { psiElement }) { // do nothing, it's already registered return@launch } @@ -124,14 +125,14 @@ class InspectionStatusChangedProbe( // if at the end of the processing cycle it's empty // we will assume they are for (loopResult in results) { - for ((idx, elementWithProblem) in elementsWithProblems.withIndex()) { - if (isElementRegistered(elementsWithProblems, loopResult.psiElement)) { + for (elementWithProblem in elementsWithProblems) { + if (isElementRegistered(elementsWithProblems, loopResult::getPsiElement)) { // the problem is still there, so don't do anything // do nothing, it's already registered break } - elementsWithProblems.removeAt(idx) + elementsWithProblems.remove(elementWithProblem) val dialect = elementWithProblem.on.get()?.component() ?: continue @@ -158,19 +159,19 @@ class InspectionStatusChangedProbe( private suspend fun isElementRegistered( elementsWithProblems: MutableList, - psiElement: PsiElement + psiElement: () -> PsiElement ): Boolean = runCatching { readAction { elementsWithProblems.containsElements { it.on.get()?.source == psiElement || - it.on.get()?.source?.isEquivalentTo(psiElement) == true + it.on.get()?.source?.isEquivalentTo(psiElement()) == true } } }.getOrDefault(false) private fun problemsByInspectionType(inspectionType: InspectionType): MutableList { val result = problemsByInspectionType.computeIfAbsent(inspectionType) { - Collections.synchronizedList(mutableListOf()) + CopyOnWriteArrayList() } result.removeAll { it.on.get() == null } diff --git a/packages/jetbrains-plugin/src/test/resources/project-fixtures/basic-java-project-with-mongodb/src/main/java/alt/mongodb/javadriver/JavaDriverRepository.java b/packages/jetbrains-plugin/src/test/resources/project-fixtures/basic-java-project-with-mongodb/src/main/java/alt/mongodb/javadriver/JavaDriverRepository.java index 4d897b23..31d5d24e 100644 --- a/packages/jetbrains-plugin/src/test/resources/project-fixtures/basic-java-project-with-mongodb/src/main/java/alt/mongodb/javadriver/JavaDriverRepository.java +++ b/packages/jetbrains-plugin/src/test/resources/project-fixtures/basic-java-project-with-mongodb/src/main/java/alt/mongodb/javadriver/JavaDriverRepository.java @@ -48,7 +48,7 @@ public Document queryMovieById(String id) { .first(); } - public List queryMoviesByYear(String year) { + public List queryMoviesByYear(int year) { return client .getDatabase("sample_mflix") .getCollection("movies") diff --git a/packages/mongodb-access-adapter/datagrip-access-adapter/src/main/kotlin/com/mongodb/jbplugin/accessadapter/datagrip/adapter/DataGripMongoDbDriver.kt b/packages/mongodb-access-adapter/datagrip-access-adapter/src/main/kotlin/com/mongodb/jbplugin/accessadapter/datagrip/adapter/DataGripMongoDbDriver.kt index 44645c3c..4bb302b3 100644 --- a/packages/mongodb-access-adapter/datagrip-access-adapter/src/main/kotlin/com/mongodb/jbplugin/accessadapter/datagrip/adapter/DataGripMongoDbDriver.kt +++ b/packages/mongodb-access-adapter/datagrip-access-adapter/src/main/kotlin/com/mongodb/jbplugin/accessadapter/datagrip/adapter/DataGripMongoDbDriver.kt @@ -12,6 +12,8 @@ import com.intellij.database.dataSource.LocalDataSource import com.intellij.database.dataSource.connection.ConnectionRequestor import com.intellij.database.run.ConsoleRunConfiguration import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.Project import com.mongodb.ConnectionString import com.mongodb.MongoClientSettings @@ -44,6 +46,8 @@ private const val TIMEOUT = 5 @OptIn(ExperimentalCoroutinesApi::class) private val mongosh = Dispatchers.IO.limitedParallelism(1) +private val logger: Logger = logger() + /** * The driver itself. Shouldn't be used directly, but through the * DataGripBasedReadModelProvider. @@ -206,8 +210,16 @@ internal class DataGripMongoDbDriver( withTimeout(timeout) { val listOfResults = mutableListOf() - val resultSet = statement.executeQuery() ?: return@withTimeout emptyList() + val queryResult = runCatching { statement.executeQuery() } + if (queryResult.isFailure) { + logger.error( + "Can not query MongoDB: $queryString", + queryResult.exceptionOrNull() + ) + return@withTimeout emptyList() + } + val resultSet = queryResult.getOrNull() ?: return@withTimeout emptyList() if (resultClass.java == Unit::class.java) { listOfResults.add(Unit as T) return@withTimeout listOfResults