summaryrefslogtreecommitdiff
path: root/runtime/jni/jni_internal.cc
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2025-06-11 14:48:25 +0100
committer Kampalus <kampalus@protonmail.ch> 2025-09-18 09:53:00 +0200
commit46bbaa3be86e01aca8d6f34c89cc90a6333fcf96 (patch)
tree37c25b0d82a0e5b7ce186857fa8531112dc868aa /runtime/jni/jni_internal.cc
parented6c006bd06ae060bd9698fd2cb25c4865512ec3 (diff)
[SP 2025-09-01] Throw an exception in JNI::NewObject for abstract classes.banksia-dev
Test: 863-serialization Bug: 421834866 Flag: EXEMPT bugfix (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:a4826745b63bdab1db7536680e1c8e947a56f7be) Merged-In: I4ccf22f85b4ae0325e9f8e29503149bbda533e86 Change-Id: I4ccf22f85b4ae0325e9f8e29503149bbda533e86
Diffstat (limited to 'runtime/jni/jni_internal.cc')
-rw-r--r--runtime/jni/jni_internal.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/runtime/jni/jni_internal.cc b/runtime/jni/jni_internal.cc
index 1dde2de741..9129d9ed41 100644
--- a/runtime/jni/jni_internal.cc
+++ b/runtime/jni/jni_internal.cc
@@ -922,6 +922,13 @@ class JNI {
if (c == nullptr) {
return nullptr;
}
+ if (UNLIKELY(!c->IsInstantiable())) {
+ soa.Self()->ThrowNewExceptionF(
+ "Ljava/lang/InstantiationException;", "Can't instantiate %s %s",
+ c->IsInterface() ? "interface" : "abstract class",
+ c->PrettyDescriptor().c_str());
+ return nullptr;
+ }
if (c->IsStringClass()) {
gc::AllocatorType allocator_type = Runtime::Current()->GetHeap()->GetCurrentAllocator();
return soa.AddLocalReference<jobject>(
@@ -949,6 +956,13 @@ class JNI {
if (c == nullptr) {
return nullptr;
}
+ if (UNLIKELY(!c->IsInstantiable())) {
+ soa.Self()->ThrowNewExceptionF(
+ "Ljava/lang/InstantiationException;", "Can't instantiate %s %s",
+ c->IsInterface() ? "interface" : "abstract class",
+ c->PrettyDescriptor().c_str());
+ return nullptr;
+ }
if (c->IsStringClass()) {
// Replace calls to String.<init> with equivalent StringFactory call.
jmethodID sf_mid = jni::EncodeArtMethod<kEnableIndexIds>(
@@ -975,6 +989,13 @@ class JNI {
if (c == nullptr) {
return nullptr;
}
+ if (UNLIKELY(!c->IsInstantiable())) {
+ soa.Self()->ThrowNewExceptionF(
+ "Ljava/lang/InstantiationException;", "Can't instantiate %s %s",
+ c->IsInterface() ? "interface" : "abstract class",
+ c->PrettyDescriptor().c_str());
+ return nullptr;
+ }
if (c->IsStringClass()) {
// Replace calls to String.<init> with equivalent StringFactory call.
jmethodID sf_mid = jni::EncodeArtMethod<kEnableIndexIds>(