diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/GenerateNotNullAssertionsTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/GenerateNotNullAssertionsTest.java index ce5fdc9980c..4c321284824 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/GenerateNotNullAssertionsTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/GenerateNotNullAssertionsTest.java @@ -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"); diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsics.java b/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsics.java index 284a33e2cf3..17efa64b247 100644 --- a/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsics.java +++ b/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsics.java @@ -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();