diff options
author | 2016-05-09 15:31:18 -0700 | |
---|---|---|
committer | 2016-05-10 09:23:08 -0700 | |
commit | 52c9da0925c67265bf353f5a66b7cb5541a88046 (patch) | |
tree | 4c6b36d9ee344c7d7b4953d6cd380f8ca53494d8 | |
parent | 266f2d4d51a18a703b2d4fbfedc63eb1baaf3ffb (diff) |
Fix issue with Constructor proxies.
Bug: 28659889
Change-Id: I4307916c79e7b56608c3ff5c9bbe83e175254f28
-rw-r--r-- | runtime/native/java_lang_reflect_Constructor.cc | 3 | ||||
-rw-r--r-- | test/044-proxy/expected.txt | 2 | ||||
-rw-r--r-- | test/044-proxy/src/ConstructorProxy.java | 53 | ||||
-rw-r--r-- | test/044-proxy/src/Main.java | 1 |
4 files changed, 58 insertions, 1 deletions
diff --git a/runtime/native/java_lang_reflect_Constructor.cc b/runtime/native/java_lang_reflect_Constructor.cc index ddcaadefa3..1e93b1c00c 100644 --- a/runtime/native/java_lang_reflect_Constructor.cc +++ b/runtime/native/java_lang_reflect_Constructor.cc @@ -47,7 +47,8 @@ static jobjectArray Constructor_getDeclaredAnnotations(JNIEnv* env, jobject java static jobjectArray Constructor_getExceptionTypes(JNIEnv* env, jobject javaMethod) { ScopedFastNativeObjectAccess soa(env); - ArtMethod* method = ArtMethod::FromReflectedMethod(soa, javaMethod); + ArtMethod* method = ArtMethod::FromReflectedMethod(soa, javaMethod) + ->GetInterfaceMethodIfProxy(sizeof(void*)); mirror::ObjectArray<mirror::Class>* result_array = method->GetDexFile()->GetExceptionTypesForMethod(method); if (result_array == nullptr) { diff --git a/test/044-proxy/expected.txt b/test/044-proxy/expected.txt index be7023e49d..2a5f0b90db 100644 --- a/test/044-proxy/expected.txt +++ b/test/044-proxy/expected.txt @@ -95,3 +95,5 @@ Proxy narrowed invocation return type passed 5.8 JNI_OnLoad called callback +Found constructor. +Found constructors with 0 exceptions diff --git a/test/044-proxy/src/ConstructorProxy.java b/test/044-proxy/src/ConstructorProxy.java new file mode 100644 index 0000000000..95d150cbbd --- /dev/null +++ b/test/044-proxy/src/ConstructorProxy.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +/** + * Tests proxies when used with constructor methods. + */ +class ConstructorProxy implements InvocationHandler { + public static void main() { + try { + new ConstructorProxy().runTest(); + } catch (Exception e) { + System.out.println("Unexpected failure occured"); + e.printStackTrace(); + } + } + + public void runTest() throws Exception { + Class<?> proxyClass = Proxy.getProxyClass( + getClass().getClassLoader(), + new Class<?>[] { Runnable.class } + ); + Constructor<?> constructor = proxyClass.getConstructor(InvocationHandler.class); + System.out.println("Found constructor."); + // We used to crash when asking the exception types of the constructor, because the runtime was + // not using the non-proxy ArtMethod + Object[] exceptions = constructor.getExceptionTypes(); + System.out.println("Found constructors with " + exceptions.length + " exceptions"); + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return args[0]; + } +} + diff --git a/test/044-proxy/src/Main.java b/test/044-proxy/src/Main.java index 1f23b95cf0..9dadb7c6ea 100644 --- a/test/044-proxy/src/Main.java +++ b/test/044-proxy/src/Main.java @@ -31,6 +31,7 @@ public class Main { NarrowingTest.main(null); FloatSelect.main(null); NativeProxy.main(args); + ConstructorProxy.main(); } // The following code maps from the actual proxy class names (eg $Proxy2) to their test output |