Use Intrinsics.checkNotNull and throw NPE in !! operator generation
This method was introduced in c204e8fc67 "just in case" and was never
used. Therefore we're free to change its semantics and use it in all new
generated code (with API version >= 1.4), without even worrying that the
newly used API will leak from inline functions in stdlib when used with
an older API version. Since we agreed to change the type of thrown
exceptions to java.lang.NPE in KT-22275, invoke a new method
throwJavaNpe now which throws that exception instead of KNPE.
Note that the additional method that takes an exception message is still
unused and exists just in case we need to use it in the future. The new
method throwJavaNpe is public also "just in case" we need to invoke it
in the future; currently it's not invoked from the bytecode.
#KT-22275 In Progress
This commit is contained in:
@@ -10,9 +10,8 @@ import kotlin.SinceKotlin;
|
||||
import kotlin.UninitializedPropertyAccessException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||
public class Intrinsics {
|
||||
private Intrinsics() {
|
||||
}
|
||||
@@ -23,13 +22,13 @@ public class Intrinsics {
|
||||
|
||||
public static void checkNotNull(Object object) {
|
||||
if (object == null) {
|
||||
throwNpe();
|
||||
throwJavaNpe();
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkNotNull(Object object, String message) {
|
||||
if (object == null) {
|
||||
throwNpe(message);
|
||||
throwJavaNpe(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +40,16 @@ public class Intrinsics {
|
||||
throw sanitizeStackTrace(new KotlinNullPointerException(message));
|
||||
}
|
||||
|
||||
@SinceKotlin(version = "1.4")
|
||||
public static void throwJavaNpe() {
|
||||
throw sanitizeStackTrace(new NullPointerException());
|
||||
}
|
||||
|
||||
@SinceKotlin(version = "1.4")
|
||||
public static void throwJavaNpe(String message) {
|
||||
throw sanitizeStackTrace(new NullPointerException(message));
|
||||
}
|
||||
|
||||
public static void throwUninitializedProperty(String message) {
|
||||
throw sanitizeStackTrace(new UninitializedPropertyAccessException(message));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user