Skip to content

Commit f780bab

Browse files
committed
Ignore breakpoints from unrecognized source files
In multi-language project non-Kotlin breakpoints would otherwise cause the debug adapter to crash with an exception.
1 parent be2cb41 commit f780bab

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

adapter/src/main/kotlin/org/javacs/ktda/classpath/PathUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private val sourceFileExtensions = setOf(".kt", ".kts", ".java")
1717
* ".../src/main/kotlin/com/abc/MyClass.kt" will be converted to
1818
* [com.abc.MyClass, com.abc.MyClassKt]
1919
*/
20-
fun toJVMClassNames(filePath: String): List<String> {
20+
fun toJVMClassNames(filePath: String): List<String>? {
2121
// TODO: Implement this using the Kotlin compiler API instead
2222
// See https://github.com/JetBrains/kotlin-netbeans/blob/c3360e8c89c1d4dac1e6f18267052ff740705079/src/main/java/org/jetbrains/kotlin/debugger/KotlinDebugUtils.java#L166-L194
2323

@@ -28,7 +28,7 @@ fun toJVMClassNames(filePath: String): List<String> {
2828
.asSequence()
2929
.find { filePath.endsWith(it) }
3030
?.let { rawClassName.dropLast(it.length) }
31-
?: throw IllegalArgumentException("Can't convert unrecognized source file '" + filePath + "' to JVM class name")
31+
?: return null
3232
val ktClassName = className
3333
.capitalizeCharAt(className.lastIndexOf(".") + 1) + "Kt" // Class name to PascalCase
3434

adapter/src/main/kotlin/org/javacs/ktda/jdi/JDIDebuggee.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import java.io.File
2626
import java.io.InputStream
2727
import java.io.OutputStream
2828
import java.nio.file.Path
29+
import java.nio.file.Paths
2930
import java.nio.charset.StandardCharsets
3031

3132
class JDIDebuggee(
@@ -99,7 +100,7 @@ class JDIDebuggee(
99100
val eventRequestManager = vm.eventRequestManager()
100101

101102
toJVMClassNames(filePath)
102-
.forEach { className ->
103+
?.forEach { className ->
103104
// Try setting breakpoint using a ClassPrepareRequest
104105

105106
for (name in listOf(className, "$className$*")) { // For local types
@@ -127,7 +128,7 @@ class JDIDebuggee(
127128
LOG.trace("Setting breakpoint at known type {}", it.name())
128129
setBreakpointAtType(it, lineNumber)
129130
}
130-
}
131+
} ?: LOG.warn("Not adding breakpoint in unrecognized source file {}", Paths.get(filePath).fileName)
131132
}
132133

133134
/** Tries to set a breakpoint - Will return whether this was successful */

0 commit comments

Comments
 (0)