reflectasm
reflectasm copied to clipboard
Unable to access methods on the Object class
I'm facing a problem where I'm not able to get any method names (and indices) through the following code:
MethodAccess.get(java.lang.Object.class)
Using getMethodNames()
will return an empty array.
I see it too:
static public void main (String[] args) throws Exception {
// prints: []
System.out.println(Arrays.asList(MethodAccess.get(java.lang.Object.class).getMethodNames()));
}
I guess no one has ever needed to call Object methods. In MethodAccess we could change:
while (nextClass != Object.class) {
addDeclaredMethodsToList(nextClass, methods);
nextClass = nextClass.getSuperclass();
}
To:
do {
addDeclaredMethodsToList(nextClass, methods);
nextClass = nextClass.getSuperclass();
} while (nextClass != Object.class);
However, this causes something else to fail. It's not clear why and I'm not sure when I'll have a chance to dig deeper.
First of all, thanks for replying! So, I've looked at this after I made my issue (to see if it was possible to just PR it instead) and all I've noticed is that two tests fail (probably because of the method indices being different.
I know that it's a bit finicky to do this but doing this change worked for me:
try {
access.invoke(new EmptyClass(), 0);
fail();
- } catch (IllegalArgumentException expected) {
+ } catch (Exception expected) {
// expected.printStackTrace();
}
try {
access.invoke(new EmptyClass(), 0, "moo");
fail();
- } catch (IllegalArgumentException expected) {
+ } catch (Exception expected) {
// expected.printStackTrace();
}
}
Not saying that it should be done this way, but it might help you find the underlying problem.
Also, I noticed that the java.lang.Object
class doesn't have a class loader so protected methods can't be called.
Sorry to bump this, any updates on this issue?