From 52a958256de5fa01897def14ee4249ceceb0fb13 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Fri, 12 Jul 2019 16:40:10 +0900 Subject: [PATCH] Debugger: Disable exception on 'variable not found' event (EA-138365) The error message is still visible to the user, so it doesn't make much sense to duplicate it as an exception. --- .../evaluate/KotlinEvaluatorBuilder.kt | 5 +--- .../evaluate/variables/VariableFinder.kt | 30 ------------------- .../evaluate/multipleBreakpoints/localFun.kt | 4 +-- 3 files changed, 3 insertions(+), 36 deletions(-) diff --git a/idea/jvm-debugger/jvm-debugger-evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluatorBuilder.kt b/idea/jvm-debugger/jvm-debugger-evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluatorBuilder.kt index f7aad2a74b5..a8ade680874 100644 --- a/idea/jvm-debugger/jvm-debugger-evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluatorBuilder.kt +++ b/idea/jvm-debugger/jvm-debugger-evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluatorBuilder.kt @@ -409,10 +409,7 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, private val sourcePositi evaluationException("Parameter evaluation is not supported for '\$default' methods") } else { status.error(EvaluationError.CannotFindVariable) - - throw VariableFinder.variableNotFound(variableFinder.context, buildString { - append("Cannot find local variable: name = '").append(name).append("', type = ").append(asmType.className) - }) + evaluationException("Cannot find local variable '$name' with type " + asmType.className) } } diff --git a/idea/jvm-debugger/jvm-debugger-evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/VariableFinder.kt b/idea/jvm-debugger/jvm-debugger-evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/VariableFinder.kt index e186034ac08..5534fd7770c 100644 --- a/idea/jvm-debugger/jvm-debugger-evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/VariableFinder.kt +++ b/idea/jvm-debugger/jvm-debugger-evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/variables/VariableFinder.kt @@ -38,36 +38,6 @@ class VariableFinder(val context: ExecutionContext) { private val USE_UNSAFE_FALLBACK: Boolean get() = true - fun variableNotFound(context: ExecutionContext, message: String): Exception { - val frameProxy = context.frameProxy - val location = frameProxy.safeLocation() - val scope = context.debugProcess.searchScope - - val locationText = location?.run { "Location: ${sourceName()}:${lineNumber()}" } ?: "No location available" - - val sourceName = location?.sourceName() - val declaringTypeName = location?.declaringType()?.name()?.replace('.', '/')?.let { JvmClassName.byInternalName(it) } - - val sourceFile = if (sourceName != null && declaringTypeName != null) { - DebuggerUtils.findSourceFileForClassIncludeLibrarySources(context.project, scope, declaringTypeName, sourceName, location) - } else { - null - } - - val sourceFileText = runReadAction { sourceFile?.text } - - if (sourceName != null && sourceFileText != null) { - val attachments = mergeAttachments( - Attachment(sourceName, sourceFileText), - Attachment("location.txt", locationText) - ) - - LOG.error(message, attachments) - } - - return EvaluateExceptionUtil.createEvaluateException(message) - } - private fun getCapturedVariableNameRegex(capturedName: String): Regex { val escapedName = Regex.escape(capturedName) val escapedSuffix = Regex.escape(INLINE_TRANSFORMATION_SUFFIX) diff --git a/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/localFun.kt b/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/localFun.kt index f48c102ff39..8cb4c83a973 100644 --- a/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/localFun.kt +++ b/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/localFun.kt @@ -16,7 +16,7 @@ fun main(args: Array) { fun myLocalFun3() { // EXPRESSION: myLocalFun1() + 1 - // RESULT: java.lang.AssertionError : Cannot find local variable: name = 'myLocalFun1', type = kotlin.jvm.functions.Function0 + // RESULT: Cannot find local variable 'myLocalFun1' with type kotlin.jvm.functions.Function0 //Breakpoint! myLocalFun1() + 1 } @@ -56,7 +56,7 @@ fun main(args: Array) { i = 1 fun myLocalFun7() { // EXPRESSION: myLocalFun6() + 1 - // RESULT: java.lang.AssertionError : Cannot find local variable: name = 'myLocalFun6', type = kotlin.jvm.functions.Function0 + // RESULT: Cannot find local variable 'myLocalFun6' with type kotlin.jvm.functions.Function0 //Breakpoint! myLocalFun6() + 1 }