From 115356b990911299c5a762084e67a8e1da1d1ea0 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Fri, 29 Jun 2018 21:29:59 +0300 Subject: [PATCH] Eval4J: Do not report certain kinds of exceptions to EA --- eval4j/src/org/jetbrains/eval4j/interpreter.kt | 6 ++---- eval4j/src/org/jetbrains/eval4j/interpreterLoop.kt | 6 ++++-- eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt | 4 ++-- eval4j/src/org/jetbrains/eval4j/values.kt | 8 ++++---- .../idea/debugger/evaluate/KotlinEvaluationBuilder.kt | 2 +- .../src/evaluate/multipleBreakpoints/exceptions.kt | 6 +++--- .../src/evaluate/multipleBreakpoints/smartcasts.kt | 2 +- .../tinyApp/src/evaluate/singleBreakpoint/unsafeCall.kt | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/eval4j/src/org/jetbrains/eval4j/interpreter.kt b/eval4j/src/org/jetbrains/eval4j/interpreter.kt index 681bd23b4a8..25dbf809cb6 100644 --- a/eval4j/src/org/jetbrains/eval4j/interpreter.kt +++ b/eval4j/src/org/jetbrains/eval4j/interpreter.kt @@ -25,8 +25,6 @@ import org.jetbrains.org.objectweb.asm.tree.analysis.Interpreter class UnsupportedByteCodeException(message: String) : RuntimeException(message) -class Eval4JInterpreterException(override val cause: Throwable) : RuntimeException(cause) - interface Eval { fun loadClass(classType: Type): Value fun loadString(str: String): Value @@ -186,7 +184,7 @@ class SingleInstructionInterpreter(private val eval: Eval) : Interpreter( when { value == NULL_VALUE -> NULL_VALUE eval.isInstanceOf(value, targetType) -> ObjectValue(value.obj(), targetType) - else -> throwEvalException(ClassCastException("${value.asmType.className} cannot be cast to ${targetType.className}")) + else -> throwInterpretingException(ClassCastException("${value.asmType.className} cannot be cast to ${targetType.className}")) } } @@ -216,7 +214,7 @@ class SingleInstructionInterpreter(private val eval: Eval) : Interpreter( } } - private fun divisionByZero(): Nothing = throw Eval4JInterpreterException(ArithmeticException("Division by zero")) + private fun divisionByZero(): Nothing = throwInterpretingException(ArithmeticException("Division by zero")) override fun binaryOperation(insn: AbstractInsnNode, value1: Value, value2: Value): Value? { return when (insn.opcode) { diff --git a/eval4j/src/org/jetbrains/eval4j/interpreterLoop.kt b/eval4j/src/org/jetbrains/eval4j/interpreterLoop.kt index f3ba9639a70..ac3cc9fd17e 100644 --- a/eval4j/src/org/jetbrains/eval4j/interpreterLoop.kt +++ b/eval4j/src/org/jetbrains/eval4j/interpreterLoop.kt @@ -64,8 +64,10 @@ abstract class ThrownFromEvalExceptionBase(cause: Throwable): RuntimeException(c override fun toString(): String = "Thrown by evaluator: ${cause}" } -class BrokenCode(cause: Throwable): ThrownFromEvalExceptionBase(cause) -class ThrownFromEvalException(cause: Throwable): ThrownFromEvalExceptionBase(cause) +class BrokenCode(cause: Throwable) : ThrownFromEvalExceptionBase(cause) + +// Interpreting exceptions should not be sent to EA +class Eval4JInterpretingException(override val cause: Throwable) : RuntimeException(cause) class ThrownFromEvaluatedCodeException(val exception: ObjectValue): RuntimeException() { override fun toString(): String = "Thrown from evaluated code: $exception" diff --git a/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt b/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt index 2bc321fef0b..7aacadc89ec 100644 --- a/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt +++ b/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt @@ -166,7 +166,7 @@ class JDIEval( return array.array().getValue(index.int).asValue() } catch (e: IndexOutOfBoundsException) { - throwEvalException(ArrayIndexOutOfBoundsException(e.message)) + throwInterpretingException(ArrayIndexOutOfBoundsException(e.message)) } } @@ -175,7 +175,7 @@ class JDIEval( return array.array().setValue(index.int, newValue.asJdiValue(vm, array.asmType.arrayElementType)) } catch (e: IndexOutOfBoundsException) { - throwEvalException(ArrayIndexOutOfBoundsException(e.message)) + throwInterpretingException(ArrayIndexOutOfBoundsException(e.message)) } } diff --git a/eval4j/src/org/jetbrains/eval4j/values.kt b/eval4j/src/org/jetbrains/eval4j/values.kt index fdc776ceef2..90ebceba101 100644 --- a/eval4j/src/org/jetbrains/eval4j/values.kt +++ b/eval4j/src/org/jetbrains/eval4j/values.kt @@ -118,15 +118,15 @@ fun Value.obj(expectedType: Type = asmType): Any? { } } -fun T?.checkNull(): T { +fun T?.checkNull(): T { if (this == null) { - throwEvalException(NullPointerException()) + throwInterpretingException(NullPointerException()) } return this } -fun throwEvalException(e: Throwable): Nothing { - throw ThrownFromEvalException(e) +fun throwInterpretingException(e: Throwable): Nothing { + throw Eval4JInterpretingException(e) } fun throwBrokenCodeException(e: Throwable): Nothing { diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluationBuilder.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluationBuilder.kt index 51d36013b4f..62ad948d8de 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluationBuilder.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluationBuilder.kt @@ -169,7 +169,7 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour LOG.debug(e) exception(e) } - catch (e: Eval4JInterpreterException) { + catch (e: Eval4JInterpretingException) { exception(e.cause) } catch (e: Exception) { diff --git a/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/exceptions.kt b/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/exceptions.kt index 55e027d23d8..73290ea2614 100644 --- a/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/exceptions.kt +++ b/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/exceptions.kt @@ -21,12 +21,12 @@ fun fail() { fun classCast() { val o = Base() // EXPRESSION: o as Derived - // RESULT: java.lang.ClassCastException: exceptions.Base cannot be cast to exceptions.Derived: Ljava/lang/ClassCastException; + // RESULT: java.lang.ClassCastException : exceptions.Base cannot be cast to exceptions.Derived //Breakpoint! val a = 1 // EXPRESSION: o as Derived - // RESULT: java.lang.ClassCastException: exceptions.Base cannot be cast to exceptions.Derived: Ljava/lang/ClassCastException; + // RESULT: java.lang.ClassCastException : exceptions.Base cannot be cast to exceptions.Derived //Breakpoint! val b = 1 } @@ -46,7 +46,7 @@ fun genericClassCast() { val c = ArrayList() c.add("a") // EXPRESSION: c.get(0) - // RESULT: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number: Ljava/lang/ClassCastException; + // RESULT: java.lang.ClassCastException : java.lang.String cannot be cast to java.lang.Number //Breakpoint! val b = 1 } diff --git a/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/smartcasts.kt b/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/smartcasts.kt index ebe4d1feb1b..c044b208780 100644 --- a/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/smartcasts.kt +++ b/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/smartcasts.kt @@ -12,7 +12,7 @@ fun main(args: Array) { // RESULT: 1: I // EXPRESSION: derived.prop -// RESULT: java.lang.ClassCastException: smartcasts.Base cannot be cast to smartcasts.Derived: Ljava/lang/ClassCastException; +// RESULT: java.lang.ClassCastException : smartcasts.Base cannot be cast to smartcasts.Derived fun test1(derived: Base) = derived is Derived && //Breakpoint! diff --git a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/unsafeCall.kt b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/unsafeCall.kt index 1a78f08827f..a442cb814ba 100644 --- a/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/unsafeCall.kt +++ b/idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/unsafeCall.kt @@ -12,4 +12,4 @@ fun main(args: Array) { // RESULT: 1: I // EXPRESSION: s2.length -// RESULT: java.lang.NullPointerException: Ljava/lang/NullPointerException; \ No newline at end of file +// RESULT: java.lang.NullPointerException \ No newline at end of file