Fix shameful assertion message error introduced after extracting method
This commit is contained in:
@@ -37,6 +37,7 @@ import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.compileJava;
|
||||
|
||||
@@ -164,6 +165,25 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
||||
assertNoIntrinsicsMethodIsCalled("A");
|
||||
}
|
||||
|
||||
public void testParamAssertionMessage() throws Exception {
|
||||
setUpEnvironment(false, false);
|
||||
|
||||
loadText("class A { fun foo(s: String) {} }");
|
||||
Class<?> a = generateClass("A");
|
||||
try {
|
||||
a.getDeclaredMethod("foo", String.class).invoke(a.newInstance(), new Object[] {null});
|
||||
}
|
||||
catch (InvocationTargetException ite) {
|
||||
Throwable e = ite.getTargetException();
|
||||
//noinspection ThrowableResultOfMethodCallIgnored
|
||||
assertInstanceOf(e, IllegalArgumentException.class);
|
||||
assertEquals("Parameter specified as non-null is null: method A.foo, parameter s", e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
fail("Assertion should have been fired");
|
||||
}
|
||||
|
||||
private void assertNoIntrinsicsMethodIsCalled(String className) {
|
||||
OutputFileCollection classes = generateClassesInFile();
|
||||
OutputFile file = classes.get(className + ".class");
|
||||
|
||||
@@ -19,7 +19,6 @@ package kotlin.jvm.internal;
|
||||
import kotlin.IntRange;
|
||||
import kotlin.KotlinNullPointerException;
|
||||
|
||||
import java.lang.Deprecated;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -70,8 +69,11 @@ public class Intrinsics {
|
||||
private static void throwParameterIsNullException(String paramName) {
|
||||
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
|
||||
|
||||
// #0 is Thread.getStackTrace(), #1 is Intrinsics.checkParameterIsNotNull, #2 is our caller
|
||||
StackTraceElement caller = stackTraceElements[2];
|
||||
// #0 Thread.getStackTrace()
|
||||
// #1 Intrinsics.throwParameterIsNullException
|
||||
// #2 Intrinsics.checkParameterIsNotNull
|
||||
// #3 our caller
|
||||
StackTraceElement caller = stackTraceElements[3];
|
||||
String className = caller.getClassName();
|
||||
String methodName = caller.getMethodName();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user