Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access methods on the Object class #75

Open
NickAcPT opened this issue Mar 8, 2020 · 3 comments
Open

Unable to access methods on the Object class #75

NickAcPT opened this issue Mar 8, 2020 · 3 comments

Comments

@NickAcPT
Copy link

NickAcPT commented Mar 8, 2020

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.

@NathanSweet
Copy link
Member

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.

@NickAcPT
Copy link
Author

NickAcPT commented Mar 10, 2020

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.

@NickAcPT
Copy link
Author

Sorry to bump this, any updates on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants