Skip to content

Commit 7b24fee

Browse files
authored
Merge pull request #2444 from digma-ai/fix-NoClassDefFoundError-KotlinLanguage
fix-NoClassDefFoundError-KotlinLanguage
2 parents a55fb15 + 50c3709 commit 7b24fee

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

jvm-common/src/main/kotlin/org/digma/intellij/plugin/idea/navigation/NavigationDiscoveryChangeService.kt

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.digma.intellij.plugin.idea.navigation
22

3-
import com.intellij.lang.java.JavaLanguage
43
import com.intellij.openapi.Disposable
54
import com.intellij.openapi.components.Service
65
import com.intellij.openapi.diagnostic.Logger
@@ -31,7 +30,6 @@ import org.digma.intellij.plugin.errorreporting.ErrorReporter
3130
import org.digma.intellij.plugin.idea.psi.isJvmSupportedFile
3231
import org.digma.intellij.plugin.log.Log
3332
import org.digma.intellij.plugin.psi.PsiUtils
34-
import org.jetbrains.kotlin.idea.KotlinLanguage
3533
import java.util.LinkedList
3634
import java.util.Queue
3735
import java.util.concurrent.ConcurrentLinkedQueue
@@ -186,19 +184,23 @@ class NavigationDiscoveryChangeService(private val project: Project, private val
186184
private inner class NavigationDiscoveryPsiTreeChangeListener : PsiTreeAnyChangeAbstractAdapter() {
187185
override fun onChange(file: PsiFile?) {
188186

189-
if (!isProjectValid(project)) {
190-
return
191-
}
187+
try {
188+
if (!isProjectValid(project)) {
189+
return
190+
}
192191

193-
//this method should be very fast, it runs on EDT.
194-
// selecting relevant files should be done while processing in background.
195-
file?.let {
196-
//very quick selection of java and kotlin files only.
197-
//when the files are processed there is another check isJvmSupportedFile, but instead of collecting
198-
// all files and checking later we check here first because there may be many files that are not relevant
199-
if (isJavaOrKotlinFile(it)) {
200-
addChangedFile(it.virtualFile)
192+
//this method should be very fast, it runs on EDT.
193+
// selecting relevant files should be done while processing in background.
194+
file?.let {
195+
//very quick selection of java and kotlin files only.
196+
//when the files are processed there is another check isJvmSupportedFile, but instead of collecting
197+
// all files and checking later we check here first because there may be many files that are not relevant
198+
if (isJavaOrKotlinFile(it)) {
199+
addChangedFile(it.virtualFile)
200+
}
201201
}
202+
} catch (e: Throwable) {
203+
ErrorReporter.getInstance().reportError("NavigationDiscoveryChangeService.NavigationDiscoveryPsiTreeChangeListener.onChange", e)
202204
}
203205
}
204206
}
@@ -222,16 +224,28 @@ class NavigationDiscoveryChangeService(private val project: Project, private val
222224
private inner class NavigationDiscoveryAsyncFileChangeListener : AsyncFileListener {
223225
override fun prepareChange(events: List<VFileEvent>): AsyncFileListener.ChangeApplier? {
224226

225-
if (!isProjectValid(project)) {
226-
return null
227-
}
227+
try {
228+
if (!isProjectValid(project)) {
229+
return null
230+
}
231+
232+
return object : AsyncFileListener.ChangeApplier {
233+
override fun afterVfsChange() {
234+
//this method should be very fast, it runs with write action.
235+
//selecting relevant files should be done while processing in background.
236+
try {
237+
addBulkEvents(events)
238+
} catch (e: Throwable) {
239+
ErrorReporter.getInstance()
240+
.reportError("NavigationDiscoveryChangeService.NavigationDiscoveryAsyncFileChangeListener.afterVfsChange", e)
241+
}
228242

229-
return object : AsyncFileListener.ChangeApplier {
230-
override fun afterVfsChange() {
231-
//this method should be very fast, it runs with write action.
232-
//selecting relevant files should be done while processing in background.
233-
addBulkEvents(events)
243+
}
234244
}
245+
} catch (e: Throwable) {
246+
ErrorReporter.getInstance()
247+
.reportError("NavigationDiscoveryChangeService.NavigationDiscoveryAsyncFileChangeListener.prepareChange", e)
248+
return null
235249
}
236250
}
237251
}
@@ -375,7 +389,8 @@ class NavigationDiscoveryChangeService(private val project: Project, private val
375389
}
376390

377391
private fun isJavaOrKotlinFile(psiFile: PsiFile): Boolean {
378-
return psiFile.language == JavaLanguage.INSTANCE || psiFile.language == KotlinLanguage.INSTANCE
392+
return psiFile.language.displayName.equals("Java", true) ||
393+
psiFile.language.displayName.equals("Kotlin", true)
379394
}
380395

381396
}

0 commit comments

Comments
 (0)