Fix incorrect message for new nullability assertion exception in 1.4

#KT-36026 Fixed
This commit is contained in:
Alexander Udalov
2020-01-20 15:48:05 +01:00
parent cc317d7548
commit 3ca0f8a569
3 changed files with 18 additions and 15 deletions
@@ -1,6 +1,4 @@
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM, JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
// FILE: Test.java // FILE: Test.java
public class Test { public class Test {
@@ -1,2 +1,2 @@
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method Foo.<init>, parameter x java.lang.NullPointerException: Parameter specified as non-null is null: method Foo.<init>, parameter x
Foo.<init>(12.kt) Foo.<init>(12.kt)
@@ -122,32 +122,37 @@ public class Intrinsics {
public static void checkParameterIsNotNull(Object value, String paramName) { public static void checkParameterIsNotNull(Object value, String paramName) {
if (value == null) { if (value == null) {
throwParameterIsNullException(paramName); throwParameterIsNullIAE(paramName);
} }
} }
public static void checkNotNullParameter(Object value, String paramName) { public static void checkNotNullParameter(Object value, String paramName) {
if (value == null) { if (value == null) {
throw sanitizeStackTrace(new NullPointerException(paramName)); throwParameterIsNullNPE(paramName);
} }
} }
private static void throwParameterIsNullException(String paramName) { private static void throwParameterIsNullIAE(String paramName) {
throw sanitizeStackTrace(new IllegalArgumentException(createParameterIsNullExceptionMessage(paramName)));
}
private static void throwParameterIsNullNPE(String paramName) {
throw sanitizeStackTrace(new NullPointerException(createParameterIsNullExceptionMessage(paramName)));
}
private static String createParameterIsNullExceptionMessage(String paramName) {
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
// #0 Thread.getStackTrace() // #0 Thread.getStackTrace()
// #1 Intrinsics.throwParameterIsNullException // #1 Intrinsics.createParameterIsNullExceptionMessage
// #2 Intrinsics.checkParameterIsNotNull // #2 Intrinsics.throwParameterIsNullIAE/throwParameterIsNullNPE
// #3 our caller // #3 Intrinsics.checkParameterIsNotNull/checkNotNullParameter
StackTraceElement caller = stackTraceElements[3]; // #4 our caller
StackTraceElement caller = stackTraceElements[4];
String className = caller.getClassName(); String className = caller.getClassName();
String methodName = caller.getMethodName(); String methodName = caller.getMethodName();
IllegalArgumentException exception = return "Parameter specified as non-null is null: method " + className + "." + methodName + ", parameter " + paramName;
new IllegalArgumentException("Parameter specified as non-null is null: " +
"method " + className + "." + methodName +
", parameter " + paramName);
throw sanitizeStackTrace(exception);
} }
public static int compare(long thisVal, long anotherVal) { public static int compare(long thisVal, long anotherVal) {