mirror of
https://github.com/corda/corda.git
synced 2025-01-06 13:08:46 +00:00
Merge pull request #334 from dicej/get-method-parameter-types
make Class.getMethod (and getConstructor) more strict about parameter ty...
This commit is contained in:
commit
a020105225
@ -43,6 +43,8 @@ public class Classes {
|
|||||||
|
|
||||||
public static native VMClass getVMClass(Object o);
|
public static native VMClass getVMClass(Object o);
|
||||||
|
|
||||||
|
public static native VMClass toVMClass(Class c);
|
||||||
|
|
||||||
private static native VMClass resolveVMClass(ClassLoader loader, byte[] spec)
|
private static native VMClass resolveVMClass(ClassLoader loader, byte[] spec)
|
||||||
throws ClassNotFoundException;
|
throws ClassNotFoundException;
|
||||||
|
|
||||||
@ -391,10 +393,25 @@ public class Classes {
|
|||||||
return new String(array, 0, array.length - 1);
|
return new String(array, 0, array.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean match(VMClass a, VMClass b) {
|
||||||
|
// TODO: in theory we should be able to just do an == comparison
|
||||||
|
// here instead of recursively comparing array element types.
|
||||||
|
// However, the VM currently can create multiple array classes for
|
||||||
|
// the same element type. We should fix that so that there's only
|
||||||
|
// ever one of each per classloader, eliminating the need for a
|
||||||
|
// recursive comparison. See also the native implementation of
|
||||||
|
// isAssignableFrom.
|
||||||
|
if (a.arrayDimensions > 0) {
|
||||||
|
return match(a.arrayElementClass, b.arrayElementClass);
|
||||||
|
} else {
|
||||||
|
return a == b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean match(Class[] a, Class[] b) {
|
public static boolean match(Class[] a, Class[] b) {
|
||||||
if (a.length == b.length) {
|
if (a.length == b.length) {
|
||||||
for (int i = 0; i < a.length; ++i) {
|
for (int i = 0; i < a.length; ++i) {
|
||||||
if (! a[i].isAssignableFrom(b[i])) {
|
if (! match(toVMClass(a[i]), toVMClass(b[i]))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,13 @@ GcField* fieldForOffset(Thread* t, object o, unsigned offset)
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
extern "C" AVIAN_EXPORT int64_t JNICALL
|
||||||
|
Avian_avian_Classes_toVMClass(Thread* t, object, uintptr_t* arguments)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<intptr_t>(
|
||||||
|
cast<GcJclass>(t, reinterpret_cast<object>(arguments[0]))->vmClass());
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" AVIAN_EXPORT void JNICALL
|
extern "C" AVIAN_EXPORT void JNICALL
|
||||||
Avian_avian_Classes_initialize(Thread* t, object, uintptr_t* arguments)
|
Avian_avian_Classes_initialize(Thread* t, object, uintptr_t* arguments)
|
||||||
{
|
{
|
||||||
|
@ -260,6 +260,15 @@ public class Reflection {
|
|||||||
.getEnclosingMethod().equals
|
.getEnclosingMethod().equals
|
||||||
(Reflection.class.getMethod
|
(Reflection.class.getMethod
|
||||||
("main", new Class[] { String[].class })));
|
("main", new Class[] { String[].class })));
|
||||||
|
|
||||||
|
Slithy.class.getMethod("tove", Gybe.class);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Slithy.class.getMethod("tove", Bandersnatch.class);
|
||||||
|
expect(false);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
// cool
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class Baz {
|
protected static class Baz {
|
||||||
@ -267,6 +276,16 @@ public class Reflection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Bandersnatch { }
|
||||||
|
|
||||||
|
class Gybe extends Bandersnatch { }
|
||||||
|
|
||||||
|
class Slithy {
|
||||||
|
public static void tove(Gybe gybe) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Foo {
|
class Foo {
|
||||||
static {
|
static {
|
||||||
if (true) throw new MyException();
|
if (true) throw new MyException();
|
||||||
|
Loading…
Reference in New Issue
Block a user