Commit bb1c6242 authored by Brian Carlstrom's avatar Brian Carlstrom
Browse files

Fix backwards check in CheckStaticMethod

Bug: 11243757
Change-Id: I559d1163ce72ab7831bd328c621519acb72975e0
parent 31b9d664
...@@ -335,7 +335,7 @@ class ScopedCheck { ...@@ -335,7 +335,7 @@ class ScopedCheck {
return; return;
} }
mirror::Class* c = soa_.Decode<mirror::Class*>(java_class); mirror::Class* c = soa_.Decode<mirror::Class*>(java_class);
if (!c->IsAssignableFrom(m->GetDeclaringClass())) { if (!m->GetDeclaringClass()->IsAssignableFrom(c)) {
JniAbortF(function_name_, "can't call static %s on class %s", JniAbortF(function_name_, "can't call static %s on class %s",
PrettyMethod(m).c_str(), PrettyClass(c).c_str()); PrettyMethod(m).c_str(), PrettyClass(c).c_str());
} }
......
...@@ -18,7 +18,28 @@ class JniTest { ...@@ -18,7 +18,28 @@ class JniTest {
public static void main(String[] args) { public static void main(String[] args) {
System.loadLibrary("arttest"); System.loadLibrary("arttest");
testFindClassOnAttachedNativeThread(); testFindClassOnAttachedNativeThread();
testCallStaticVoidMethodOnSubClass();
} }
private static native void testFindClassOnAttachedNativeThread(); private static native void testFindClassOnAttachedNativeThread();
private static void testCallStaticVoidMethodOnSubClass() {
testCallStaticVoidMethodOnSubClassNative();
if (!testCallStaticVoidMethodOnSubClass_SuperClass.executed) {
throw new AssertionError();
}
}
private static native void testCallStaticVoidMethodOnSubClassNative();
private static class testCallStaticVoidMethodOnSubClass_SuperClass {
private static boolean executed = false;
private static void execute() {
executed = true;
}
}
private static class testCallStaticVoidMethodOnSubClass_SubClass
extends testCallStaticVoidMethodOnSubClass_SuperClass {
}
} }
...@@ -54,6 +54,7 @@ static void* testFindClassOnAttachedNativeThread(void*) { ...@@ -54,6 +54,7 @@ static void* testFindClassOnAttachedNativeThread(void*) {
return NULL; return NULL;
} }
// http://b/10994325
extern "C" JNIEXPORT void JNICALL Java_JniTest_testFindClassOnAttachedNativeThread(JNIEnv*, extern "C" JNIEXPORT void JNICALL Java_JniTest_testFindClassOnAttachedNativeThread(JNIEnv*,
jclass) { jclass) {
pthread_t pthread; pthread_t pthread;
...@@ -65,3 +66,18 @@ extern "C" JNIEXPORT void JNICALL Java_JniTest_testFindClassOnAttachedNativeThre ...@@ -65,3 +66,18 @@ extern "C" JNIEXPORT void JNICALL Java_JniTest_testFindClassOnAttachedNativeThre
int pthread_join_result = pthread_join(pthread, NULL); int pthread_join_result = pthread_join(pthread, NULL);
assert(pthread_join_result == 0); assert(pthread_join_result == 0);
} }
// http://b/11243757
extern "C" JNIEXPORT void JNICALL Java_JniTest_testCallStaticVoidMethodOnSubClassNative(JNIEnv* env,
jclass) {
jclass super_class = env->FindClass("JniTest$testCallStaticVoidMethodOnSubClass_SuperClass");
assert(super_class != NULL);
jmethodID execute = env->GetStaticMethodID(super_class, "execute", "()V");
assert(execute != NULL);
jclass sub_class = env->FindClass("JniTest$testCallStaticVoidMethodOnSubClass_SubClass");
assert(sub_class != NULL);
env->CallStaticVoidMethod(sub_class, execute);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment