I looked into the code and found the following Problem with this particiular code (com.sun.jdi) implementation:
I think the problem stems from within Reflector.java's invokeMatchingMethod with signature (String methodName, List methods, Object target, Object[] args) : (1) target.getClass() == EventRequestManagerImpl $MethodEntryRequestImpl (2) the list of methods has two entries: a) the first method has a declaring class of EventRequestManagerImpl $MethodEntryRequestImpl b) the second method has a declaring class of com.sun.tools.jdi.EventRequestManagerImpl$ClassVisibleEventRequestImpl (higher in the hierarchy?) (3) if multiple methods completely match the parameters then the last entry wins! (4) neither 2a) or 2b) are public classes (5) going through the inheritance hierachy of 2b) does not find any method that is public and equals method 2b) otherwise In my point of view there are two solutions within the invokeMatchingMethod: I) if there are several matching methods take the method that has getDeclaringClass == target.getClass II) backtracking if there are several methods (not simply taking the last and throwing an Exception) The ultimate question is why are there two methods in the list. I did look that far. What do you think? -- Jakob On Jan 11, 10:55 pm, jpraher <j...@hapra.at> wrote: > Hi all, > > first of all kudos to clojure. Especially the clojure-swank in > combination with leinigen is a nice environment to work with. > > Now to my problem: > I am playing with JDI to intercept events of an attached JVM via > clojure. Since there are a lot of siblings eventrequest subinterfaces, > which can be obtained by working with a factory called > eventrequestmanager, I am using a construct like the following: > > (def METHOD_ENTRY 'createMethodEntryRequest) > > (defmacro create-request > [event-manager kind] > (let [k (eval kind)] > `(. ~event-manager ~k))) > > ; the usage is something like: > (let [event-request (create-request my-event-manager METHOD_ENTRY)] > (.addClassFilter event-request "some.package.*") > (.enable event-request)) > > ; now the problem is that addClassFilter is defined in a public > interface, yet is implemented is an anonymous inner class, that is > apparently non-public > ; so I get the following exception: > > Can't call public method of non-public class: public synchronized void > com.sun.tools.jdi.EventRequestManagerImpl > $ClassVisibleEventRequestImpl.addClassFilter(java.lang.String) > [Thrown class java.lang.IllegalArgumentException] > > Backtrace: > 0: clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:85) > 1: clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28) > ... > > By using type hints I can circumvent the problem, see below. > > I do not know how to use type hinting whithin the above macro, since > the return type is specified indirectly in the parameter that is given > (this provides the method to be invoked). So I cannot declare a static > return type of a macro (would this be possible at all?). I tried > (cast) but this does not help either. What should I do? > > To summarize: > > user> (def *method-entry* (debug/create-request (debug/event-request- > manager *vm*) debug/METHOD_ENTRY)) > #'user/*method-entry* > > ; static workaround: declare the type of the variable to be the public > interface > user> (def #^{:tag com.sun.jdi.request.MethodEntryRequest} me *method- > entry*) > #'user/me > > ; addClassFilter does not work with the raw instance returned > user> (.addClassFilter *method-entry* "test") > ; Evaluation aborted. > > ; addClassFilter does however work with a type hinted to be the > interface type. > user> (.addClassFilter me "test") > nil > > What would u suggest? > Thanks for help. > -- Jakob
-- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en