4 Replies Latest reply: Mar 21, 2009 8:26 AM by 843810 RSS

    Classloader exception in Java debugger built using JDI - Please reply

    843810
      Im a newbie to java & ive been trying to develop a simple java debugger & ive been getting the following set of exception ir-respective of ip file given to debug


      Exception:::java.lang.ClassLoader.loadClass(java.lang.String, boolean)
      Exception:::java.lang.ClassLoader.loadClass(java.lang.String, boolean)
      Exception:::java.lang.ClassLoader.loadClass(java.lang.String, boolean)
      Exception in thread "Thread-0" java.util.NoSuchElementException
      at com.sun.tools.jdi.EventSetImpl$Itr.next(EventSetImpl.java:822)
      at com.sun.tools.jdi.EventSetImpl$Itr.nextEvent(EventSetImpl.java:827)
      at jds.Executepgm.run(Executepgm.java:48)

      Can someone reply please its very urgent

      ive attached the code here

      MAIN CLASS


      package jds;

      import com.sun.jdi.VirtualMachine;
      import java.io.*;


      public class JDS {



      public static void main(String[] args) {
      if(args.length == 0 || args[0].equalsIgnoreCase("-help")|| args.length>1)
      {
      help();
      System.exit(0);
      }

      LaunchVM lvm = new LaunchVM();
      String str= new String();
      str = readstr();
      if (str.contains("run"))
      {
      String str2 =new String();
      try
      {
      str2 = args[0]+str.substring(3);
      }
      catch(StringIndexOutOfBoundsException e)
      {
      str2=args[0];
      }
      VirtualMachine vm = lvm.launchTarget(str2);
      vm.setDebugTraceMode(0);
      Executepgm expm =new Executepgm(vm);
      System.out.println("run cmd");
      expm.runpgm(vm);
      expm.start();
      vm.resume();
      }

      }
      static void help() {
           System.out.println("**Usage: java JDS <class> **");
      }

      static String readstr()
      {
      String str = new String();
      BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
      try
      {
      str= stdin.readLine();
      }
      catch (IOException ioe) {
      System.out.println("Recieved exception: "+ioe);
      System.exit(1);
      }
      return str;
      }
      }


      SUPPORT CLASS


      package jds;
      import com.sun.jdi.*;
      import com.sun.jdi.event.*;
      import com.sun.jdi.request.*;


      public class Executepgm extends Thread{
      private VirtualMachine vm;
      String[] excludes = {"java.*", "javax.*", "sun.*",
                          "com.sun.*"};

      Executepgm(VirtualMachine vm)
      {
      this.vm=vm;
      }

      public void run()
      {
      EventQueue queue = vm.eventQueue();
      boolean connected = true;
      while(connected == true)
      try {
      EventSet eventSet = queue.remove();
      EventIterator it = eventSet.eventIterator();
      while (it.hasNext()) {
      Event et=it.nextEvent();
      if(et instanceof MethodEntryEvent)
      System.out.println("method entry"+et);
      else if (et instanceof MethodExitEvent)
      System.out.println("method exit"+et);
      else if (et instanceof ExceptionEvent)
      {
      try
      {
      System.out.println("Exception:::"+((ExceptionEvent)et).catchLocation().method());
      }
      catch(NullPointerException e)
      {
      et=it.nextEvent();

      }
      }
      else if(et instanceof VMDisconnectEvent)
      connected = false;
      }

      eventSet.resume();
      } catch (InterruptedException exc) {
      System.out.println("Interrupted");
      } catch (VMDisconnectedException discExc) {

      }
      }
      void runpgm(VirtualMachine vm)
      {
      EventRequestManager erm = vm.eventRequestManager();
      ExceptionRequest excReq = erm.createExceptionRequest(null,true, true);

      excReq.setSuspendPolicy(EventRequest.SUSPEND_ALL);
      excReq.enable();
      MethodEntryRequest menr = erm.createMethodEntryRequest();
      for (int i=0; i<excludes.length; ++i) {
      menr.addClassFilter(excludes);
      }
      menr.setSuspendPolicy(EventRequest.SUSPEND_NONE);
      menr.enable();

      MethodExitRequest mexr = erm.createMethodExitRequest();
      for (int i=0; i<excludes.length; ++i) {
      mexr.addClassFilter(excludes[i]);
      }
      mexr.setSuspendPolicy(EventRequest.SUSPEND_NONE);
      mexr.enable();
      }

      }