Eval4J: Do not report certain kinds of exceptions to EA
This commit is contained in:
@@ -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<Value>(
|
||||
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<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? {
|
||||
return when (insn.opcode) {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
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 {
|
||||
|
||||
+1
-1
@@ -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) {
|
||||
|
||||
+3
-3
@@ -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<String>()
|
||||
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
|
||||
}
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ fun main(args: Array<String>) {
|
||||
// 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!
|
||||
|
||||
@@ -12,4 +12,4 @@ fun main(args: Array<String>) {
|
||||
// RESULT: 1: I
|
||||
|
||||
// EXPRESSION: s2.length
|
||||
// RESULT: java.lang.NullPointerException: Ljava/lang/NullPointerException;
|
||||
// RESULT: java.lang.NullPointerException
|
||||
Reference in New Issue
Block a user