If an EventRequest has a thread filter and that thread has TERMINATED, calling EventRequest.disable() will result in an IllegalThreadStateException. This is not per the spec, which mentions no such exception, and is something that can routinely happen. You just need for the filter thread to exit while the EventRequest is still enabled, and then later you disable the EventRequest.
The exception originates in the debug agent. eventFilterRestricted_deinstall() calls disableEvents() to disable any events associated with the EventRequest. If the EventRequest has a filter, then JVMTI SetEventNotificationMode() gets called with the thread as an argument. JVMTI returns JVMTI_ERROR_THREAD_NOT_ALIVE, which gets converted to JDWP INVALID_THREAD, which JDI converts to IllegalThreadStateException.
Probably the best solution is in EventRequestImpl::clearCommand() we add a check for JVMTI_ERROR_THREAD_NOT_ALIVE and simply swallow it. We could also possibly instead do this further up call change closer to when the failure actually happens, even right after the SetEventNotificationMode() call. For now I'm inclined to just do it in EventRequestImpl::clearCommand() since it seems to be the only places impacted by this issue.
The exception originates in the debug agent. eventFilterRestricted_deinstall() calls disableEvents() to disable any events associated with the EventRequest. If the EventRequest has a filter, then JVMTI SetEventNotificationMode() gets called with the thread as an argument. JVMTI returns JVMTI_ERROR_THREAD_NOT_ALIVE, which gets converted to JDWP INVALID_THREAD, which JDI converts to IllegalThreadStateException.
Probably the best solution is in EventRequestImpl::clearCommand() we add a check for JVMTI_ERROR_THREAD_NOT_ALIVE and simply swallow it. We could also possibly instead do this further up call change closer to when the failure actually happens, even right after the SetEventNotificationMode() call. For now I'm inclined to just do it in EventRequestImpl::clearCommand() since it seems to be the only places impacted by this issue.