4 Replies Latest reply: Apr 7, 2008 12:20 PM by 800575 RSS

    Annotation Processing via JDI

      I would like to process annotations using JDI , and i check out [http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4728827] that was at 2002 and it was not yet implemented. is it implemented now?
        • 1. Re: Annotation Processing via JDI
          No. Others have used JDI's invokeMethod to invoke the methods in java.lang.reflect to get annotations. This can get a bit complicated
          because you need a thread in which to do the invokeMethod. Others have started a special thread for this, eg:

          - create/enable a ThreadStartRequest with SUSPEND_THREAD
          - get the JDI ClassType object for Thread -> xxx
          - call xxx.newInstance to create a new Thread in the debuggee -> myThread
          - use invokeMethod to call myThread.start()
          - you will get a ThreadStart event for this thread, and
          the thread will be suspended.
          - resume the event

          Leave the thread suspended and use it to do all/some of your expression
          • 2. Re: Annotation Processing via JDI
            But will i be able to process local variables using java reflection ? use AccessibleObject ? Also i would be needing to know if there is an annotation at a specific line in the source code , i checked out Java Reflection API and there is no "location" associated with Accessible Objects

            Edited by: 3ashmawy on Apr 4, 2008 3:42 PM

            Edited by: 3ashmawy on Apr 4, 2008 3:45 PM
            • 3. Re: Annotation Processing via JDI
              I began to implement as we discussed but the first weird problem appeard . In the method i handle for the ThreadStartEvent and it's code is as follows:
                   private void threadStartEvent(ThreadStartEvent event){
                        System.out.println("A Thread Start event happened !");
                        ThreadReference thRef;
                        try {
                             thRef = event.thread().getClass().newInstance();
                        } catch (InstantiationException e) {
                             // TODO Auto-generated catch block
                        } catch (IllegalAccessException e) {
                             // TODO Auto-generated catch block

              An InstantiationException is thrown and this is its stacktrace

              java.lang.InstantiationException: com.sun.tools.jdi.ThreadReferenceImpl
                   at java.lang.Class.newInstance0(Class.java:340)
                   at java.lang.Class.newInstance(Class.java:308)
                   at DebugEventThread.threadStartEvent(DebugEventThread.java:551)
                   at DebugEventThread.handleEvent(DebugEventThread.java:502)
                   at DebugEventThread.doInBackground(DebugEventThread.java:151)
                   at DebugEventThread.doInBackground(DebugEventThread.java:1)
                   at javax.swing.SwingWorker$1.call(SwingWorker.java:278)
                   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
                   at java.util.concurrent.FutureTask.run(FutureTask.java:138)
                   at javax.swing.SwingWorker.run(SwingWorker.java:317)
                   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
                   at java.lang.Thread.run(Thread.java:619)

              The thread i am trying to do .newInstance() is not abstract nor an interface ... So Why this is happening ?
              • 4. Re: Annotation Processing via JDI
                The code is creating a new instance of the JDI object ThreadReferenceImpl when what you should be doing
                is using the JDI invokeMethod method to create a new Thread object in the debuggee.