Eval4J: Do not report certain kinds of exceptions to EA

This commit is contained in:
Yan Zhulanow
2018-06-29 21:29:59 +03:00
parent d8bab58b2c
commit 115356b990
8 changed files with 18 additions and 18 deletions
@@ -25,8 +25,6 @@ import org.jetbrains.org.objectweb.asm.tree.analysis.Interpreter
class UnsupportedByteCodeException(message: String) : RuntimeException(message) class UnsupportedByteCodeException(message: String) : RuntimeException(message)
class Eval4JInterpreterException(override val cause: Throwable) : RuntimeException(cause)
interface Eval { interface Eval {
fun loadClass(classType: Type): Value fun loadClass(classType: Type): Value
fun loadString(str: String): Value fun loadString(str: String): Value
@@ -186,7 +184,7 @@ class SingleInstructionInterpreter(private val eval: Eval) : Interpreter<Value>(
when { when {
value == NULL_VALUE -> NULL_VALUE value == NULL_VALUE -> NULL_VALUE
eval.isInstanceOf(value, targetType) -> ObjectValue(value.obj(), targetType) 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<Value>(
} }
} }
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? { override fun binaryOperation(insn: AbstractInsnNode, value1: Value, value2: Value): Value? {
return when (insn.opcode) { return when (insn.opcode) {
@@ -64,8 +64,10 @@ abstract class ThrownFromEvalExceptionBase(cause: Throwable): RuntimeException(c
override fun toString(): String = "Thrown by evaluator: ${cause}" override fun toString(): String = "Thrown by evaluator: ${cause}"
} }
class BrokenCode(cause: Throwable): ThrownFromEvalExceptionBase(cause) class BrokenCode(cause: Throwable) : ThrownFromEvalExceptionBase(cause)
class ThrownFromEvalException(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() { class ThrownFromEvaluatedCodeException(val exception: ObjectValue): RuntimeException() {
override fun toString(): String = "Thrown from evaluated code: $exception" override fun toString(): String = "Thrown from evaluated code: $exception"
@@ -166,7 +166,7 @@ class JDIEval(
return array.array().getValue(index.int).asValue() return array.array().getValue(index.int).asValue()
} }
catch (e: IndexOutOfBoundsException) { 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)) return array.array().setValue(index.int, newValue.asJdiValue(vm, array.asmType.arrayElementType))
} }
catch (e: IndexOutOfBoundsException) { catch (e: IndexOutOfBoundsException) {
throwEvalException(ArrayIndexOutOfBoundsException(e.message)) throwInterpretingException(ArrayIndexOutOfBoundsException(e.message))
} }
} }
+4 -4
View File
@@ -118,15 +118,15 @@ fun Value.obj(expectedType: Type = asmType): Any? {
} }
} }
fun <T: Any> T?.checkNull(): T { fun <T : Any> T?.checkNull(): T {
if (this == null) { if (this == null) {
throwEvalException(NullPointerException()) throwInterpretingException(NullPointerException())
} }
return this return this
} }
fun throwEvalException(e: Throwable): Nothing { fun throwInterpretingException(e: Throwable): Nothing {
throw ThrownFromEvalException(e) throw Eval4JInterpretingException(e)
} }
fun throwBrokenCodeException(e: Throwable): Nothing { fun throwBrokenCodeException(e: Throwable): Nothing {
@@ -169,7 +169,7 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour
LOG.debug(e) LOG.debug(e)
exception(e) exception(e)
} }
catch (e: Eval4JInterpreterException) { catch (e: Eval4JInterpretingException) {
exception(e.cause) exception(e.cause)
} }
catch (e: Exception) { catch (e: Exception) {
@@ -21,12 +21,12 @@ fun fail() {
fun classCast() { fun classCast() {
val o = Base() val o = Base()
// EXPRESSION: o as Derived // 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! //Breakpoint!
val a = 1 val a = 1
// EXPRESSION: o as Derived // 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! //Breakpoint!
val b = 1 val b = 1
} }
@@ -46,7 +46,7 @@ fun genericClassCast() {
val c = ArrayList<String>() val c = ArrayList<String>()
c.add("a") c.add("a")
// EXPRESSION: c.get(0) // 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! //Breakpoint!
val b = 1 val b = 1
} }
@@ -12,7 +12,7 @@ fun main(args: Array<String>) {
// RESULT: 1: I // RESULT: 1: I
// EXPRESSION: derived.prop // 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) = fun test1(derived: Base) =
derived is Derived && derived is Derived &&
//Breakpoint! //Breakpoint!
@@ -12,4 +12,4 @@ fun main(args: Array<String>) {
// RESULT: 1: I // RESULT: 1: I
// EXPRESSION: s2.length // EXPRESSION: s2.length
// RESULT: java.lang.NullPointerException: Ljava/lang/NullPointerException; // RESULT: java.lang.NullPointerException