This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 16795

Summary: debuggercore assumes each debugger only handles one session
Product: debugger Reporter: Torbjorn Norbye <tor>
Component: CodeAssignee: Jan Jancura <jjancura>
Status: CLOSED FIXED    
Severity: blocker    
Priority: P2    
Version: 3.x   
Hardware: Sun   
OS: SunOS   
Issue Type: DEFECT Exception Reporter:

Description Torbjorn Norbye 2001-10-20 00:07:19 UTC
I'm debugging two sessions, and then I click on Finish debugger.

I get this exception:

9 14:19:20 PDT 2001: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.RangeCheck(ArrayList.java:491)
        at java.util.ArrayList.get(ArrayList.java:307)
        at
 org.netbeans.modules.debugger.multisession.EnterpriseDebugger.finishDebuggerIn(EnterpriseDebugger.java:516)
        at
 org.netbeans.modules.debugger.multisession.EnterpriseDebugger.finishDebugger(EnterpriseDebugger.java:209)
        at
 org.netbeans.modules.debugger.support.actions.FinishAction.performAction(FinishAction.java:58)
        at
org.openide.util.actions.CallableSystemAction.actionPerformed(CallableSystemAction.java:66)
        at org.netbeans.core.ModuleActions$1.run(ModuleActions.java:105)
        at org.openide.util.Task.run(Task.java:152)
[catch] at
org.openide.util.RequestProcessor$ProcessorThread.run(RequestProcessor.java:611)


This is because of this code in EnterpriseDebugger:

            // finish all non persistent sessions
            int i = debuggers.size () - 1;
            for (; i >= 0; i--) {
                Session s = (Session) debuggers.get (i);
                s.finish ();
            }

This fails because sessions and debuggers are not one-to-one.
In particular, my DebuggerImpl.createDebugger returns the same object for each
new session that is started (one controls all of them - this is
important because it often hands off control from one session
to another, for example, if a program forks).


The fix is to alter the Session.finish() implementation 
such that it only calls Debugger.finishDebugger() if none of the other 
session objects's getDebugger() methods return the same debugger. 
(If they are not the last session, just call removeSession() instead).

In other words, only the last Session that is associated with a debugger 
should call finishDebugger().  But perhaps that is more than you want to 
deal with at this late stage.

With this fixed, I'll also be able to call Session.finish() when one
particular session finishes, without that implying that the debugger
is finished.

Here is the modified version of Session which implements this fix:
Index: Session.java
===================================================================
RCS file:
/cvs/debuggercore/src/org/netbeans/modules/debugger/multisession/Session.java,v
retrieving revision 1.4
diff -c -r1.4 Session.java
*** Session.java 16 Oct 2001 12:13:11 -0000  1.4
--- Session.java 19 Oct 2001 23:03:26 -0000
***************
*** 450,455 ****
--- 450,469 ----
      }
  
      void finishIn () {
+     // See if any other sessions are being debugged by this debugger:
+     Session[] allSessions = sessionDebugger.getSessions();
+     int n = allSessions.length;
+     if (allSessions != null) {
+         for (int i = 0; i < n; i++) {
+       if ((allSessions[i] != this) &&
+           (allSessions[i].getDebugger() == getDebugger())) {
+           // Just remove this session
+                     sessionDebugger.removeSession (this);
+           return;
+       }
+         }
+     }
+     // This is the last session being debugged by this debugger - finish it
          try {
              ((AbstractDebugger) getDebugger ()).finishDebugger ();
              //      setConnectionState (STATE_NOT_RUNNING);
Comment 1 Jan Jancura 2001-10-22 16:54:11 UTC
in main trunk
Comment 2 Jan Stola 2001-10-29 16:21:27 UTC
Closed.