-
1. Re: findMethodByHash & Unable to figure out calledmethod of
marciodel Sep 22, 2004 12:51 PM (in response to marciodel)I have changed the method
findMethodByHash
and my code is working now. Is it a general solution?
public static Method findMethodByHash(Class clazz, long hash) throws Exception
{
System.out.println("findMethodByHash " + clazz.getName());
Method[] methods = clazz.getDeclaredMethods();
for (int i = 0; i < methods.length; i++)
{
System.out.println("methodHash " + methods.getName() + " " + methodHash(methods));
if (methodHash(methods) == hash) return methods;
}
System.out.println("clazz.getSuperclass() " + clazz.getSuperclass());
if (clazz.getSuperclass() != null)
{
return findMethodByHash(clazz.getSuperclass(), hash);
}
Class[] intfs = clazz.getInterfaces();
if(intfs != null || intfs.length != 0 ){
for (int i = 0; i < intfs.length; i++) {
Method result = findMethodByHash(intfs, hash);
if(result != null)
return result;
}
}
return null;
}
Thanks, -
2. Re: findMethodByHash &
bill.burke Sep 22, 2004 1:03 PM (in response to marciodel)Your pointcut expression was incorrect. You must do
call(* $instanceof{java.sql.Connection}->*(..))
Unfortunately, $instanceof cannot take wildcards at this time.
If this is it, let me know.
Thanks,
Bill -
3. Re: findMethodByHash &
marciodel Sep 23, 2004 9:18 AM (in response to marciodel)The problem is that I am defining:
call(javax.microedition.io.*->*(..))
There is an interface javax.microedition.io.Connection in the package. My class is using javax.wireless.messaging.MessageConnection that extends javax.microedition.io.Connection. The code in bold below is being changed by JBossAOP, for javax.wireless.messaging.MessageConnection extends javax.microedition.io.Connection. But the probrem is that resolveCallerMethodInfo can not find the method close() in javax.wireless.messaging.MessageConnection, for close() is declared in javax.microedition.io.Connection. Then the exception is thrown. The method findMethodByHash only tries to find the method in the superclass, but javax.wireless.messaging.MessageConnection is an interface and don't have superclasses. It only extends interfaces (Class.getInterfaces()).
javax.wireless.messaging.MessageConnection conn....
...
...
conn.close();
Thanks,
Marcio Alves -
4. Re: findMethodByHash &
kevinconner Sep 23, 2004 11:25 AM (in response to marciodel)Hiya Bill.
The issue is that the findMethodByHash method assumes that the clazz argument is a class, in this case it is an interface. The bug is that the method being searched is in a super interface of the one being called, hence it is never found.
I have a simple test case that reproduces it and a patch that is very similar to the one Marcio suggested.public static Method findMethodByHash(Class clazz, long hash) throws Exception { Method[] methods = clazz.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { if (methodHash(methods) == hash) return methods; } if (clazz.isInterface()) { final Class[] interfaces = clazz.getInterfaces() ; final int numInterfaces = interfaces.length ; for(int count = 0 ; count < numInterfaces ; count++) { final Method method = findMethodByHash(interfaces[count], hash) ; if (method != null) { return method ; } } } else if (clazz.getSuperclass() != null) { return findMethodByHash(clazz.getSuperclass(), hash); } return null; }
-
5. Re: findMethodByHash &
kabirkhan Sep 23, 2004 11:29 AM (in response to marciodel)Hi,
Looks reasonable. Can you please post the testcase?
Cheers,
Kabir -
6. Re: findMethodByHash &
kabirkhan Sep 23, 2004 11:33 AM (in response to marciodel)Or send it to me at kabir.khan a jboss.org
-
7. Re: findMethodByHash &
bill.burke Sep 23, 2004 11:36 AM (in response to marciodel)the bug is that he is using the AOP framework incorrectly. He must use $instanceof{}. But, $instanceof{} is not complete in that it needs to support wildcards and annotations which it does not now.
But, I'll add the fix to findMethodHash anyways.
Bill -
8. Re: findMethodByHash &
kevinconner Sep 23, 2004 11:37 AM (in response to marciodel)I'll link it in to the basic.AOPTester and send the patch to you.
Kev -
9. Re: findMethodByHash &
kevinconner Sep 23, 2004 11:58 AM (in response to marciodel)Sorry Bill, just noticed your posting.
The problem happens when you use $instanceof{}. If you do not use it then the call does not get intercepted.
Kev -
10. Re: findMethodByHash &
marciodel Sep 23, 2004 3:13 PM (in response to marciodel)Bill, Kevin and Kabir, thank you for the help.
Best regards,
Marcio Alves -
11. Re: findMethodByHash &
bill.burke Sep 23, 2004 3:29 PM (in response to marciodel)BTW, the fix to findMethodByHash is in CVS and will be in RC2 on Friday.
Bill