diff options
| author | Andy McFadden <fadden@android.com> | 2009-04-30 17:47:50 -0700 |
|---|---|---|
| committer | Andy McFadden <fadden@android.com> | 2009-05-01 12:15:15 -0700 |
| commit | dc5ffb8e544e533a269960ddb78e38fb491d8ab6 (patch) | |
| tree | b34fb1092a18df0321ba9c2f76fdac02555bb493 /vm/native | |
| parent | 2c98747b403970ef4b3352e271633f93935b9825 (diff) | |
| download | android_dalvik-dc5ffb8e544e533a269960ddb78e38fb491d8ab6.tar.gz android_dalvik-dc5ffb8e544e533a269960ddb78e38fb491d8ab6.tar.bz2 android_dalvik-dc5ffb8e544e533a269960ddb78e38fb491d8ab6.zip | |
Corrected behavior of Constructor.newInstance on abstract classes.
The VM now throws an exception when somebody tries to create an instance
of an abstract class through a Constructor object. It also ensures that
the class is initialized before attempting to create an instance.
This change adds some Constructor tests to the 042-new-instance VM test.
(It also pulls in some additions that were made to the 042 test back
in March, on the p4 master branch.)
Diffstat (limited to 'vm/native')
| -rw-r--r-- | vm/native/java_lang_reflect_Constructor.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/vm/native/java_lang_reflect_Constructor.c b/vm/native/java_lang_reflect_Constructor.c index 82b72eee3..6878f7b5a 100644 --- a/vm/native/java_lang_reflect_Constructor.c +++ b/vm/native/java_lang_reflect_Constructor.c @@ -39,6 +39,12 @@ static void Dalvik_java_lang_reflect_Constructor_getConstructorModifiers( /* * public int constructNative(Object[] args, Class declaringClass, * Class[] parameterTypes, int slot, boolean noAccessCheck) + * + * We get here through Constructor.newInstance(). The Constructor object + * would not be available if the constructor weren't public (per the + * definition of Class.getConstructor), so we can skip the method access + * check. We can also safely assume the constructor isn't associated + * with an interface, array, or primitive class. */ static void Dalvik_java_lang_reflect_Constructor_constructNative( const u4* args, JValue* pResult) @@ -52,6 +58,22 @@ static void Dalvik_java_lang_reflect_Constructor_constructNative( Object* newObj; Method* meth; + if (dvmIsAbstractClass(declaringClass)) { + dvmThrowExceptionWithClassMessage("Ljava/lang/InstantiationException;", + declaringClass->descriptor); + RETURN_VOID(); + } + + /* initialize the class if it hasn't been already */ + if (!dvmIsClassInitialized(declaringClass)) { + if (!dvmInitClass(declaringClass)) { + LOGW("Class init failed in Constructor.constructNative (%s)\n", + declaringClass->descriptor); + assert(dvmCheckException(dvmThreadSelf())); + RETURN_VOID(); + } + } + newObj = dvmAllocObject(declaringClass, ALLOC_DEFAULT); if (newObj == NULL) RETURN_PTR(NULL); |
