Skip to content

Commit

Permalink
Merge master to Beta Java 20 (#189)
Browse files Browse the repository at this point in the history
* Catch and log exceptions from IJDIEventListener during event dispatch

IF IJDIEventListener.handleEvent() throws an exception during
EventDispatcher.dispatch(), the debugger breaks. Stepping, resuming,
terminating, etc. doesn't work.

This change adds a try-catch block around
IJDIEventListener.handleEvent() in EventDispatcher.dispatch(), to ensure
faulty listeners don't break the debugger.

Fixes: #172

* Disable GC for exception in ExceptionEvent until event is processed

This change disables garbage collection for
ExceptionEventImpl.fException, until the event is processed by listeners
in EventDispatcher.dispatch().

Fixes: #167

* Check if AskRecurrenceDialog was cancelled and has null result (#176)

Fixes #176

* Remove references to deprecated Navigator in Scrapbook editor

It's up for removal thus offering it makes no sense.

* Clean up duplicated code in JavaRuntime

Replace the code checking if a classpath entry is modular with the new
ClasspathEntry.isModular().

Fixes: #184

---------

Co-authored-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
Co-authored-by: Andrey Loskutov <loskutov@gmx.de>
Co-authored-by: Александър Куртаков <akurtakov@gmail.com>
  • Loading branch information
4 people committed Mar 3, 2023
1 parent 601a7c2 commit 890a4ee
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@ public boolean shouldSkipSubsequentOccurrence(JDIThread thread, IJavaExceptionBr
if (skip == SuspendOnRecurrenceStrategy.RECURRENCE_UNCONFIGURED) {
skip = new AskRecurrenceDialog(JDIDebugUIPlugin.getShell()).getAnswer();
}
if (skip == null) {
return false; // user didn't understand the question and cancelled dialog
}
switch (skip) {
case SKIP_RECURRENCES:
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -107,7 +107,6 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
Expand Down Expand Up @@ -1446,14 +1445,7 @@ public void run() {
@Override
public <T> T getAdapter(Class<T> required) {
if (required == IShowInTargetList.class) {
return (T) new IShowInTargetList() {
@SuppressWarnings("deprecation")
@Override
public String[] getShowInTargetIds() {
return new String[] { JavaUI.ID_PACKAGES, IPageLayout.ID_RES_NAV };
}

};
return (T) (IShowInTargetList) () -> new String[] { JavaUI.ID_PACKAGES };
}
return super.getAdapter(required);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class ExceptionEventImpl extends LocatableEventImpl implements
private ObjectReferenceImpl fException;
/** Location of catch, or 0 if not caught. */
private LocationImpl fCatchLocation;
/** Whether garbage collection has been re-enabled for the exception. */
private boolean fExceptionCollectionEnabled;

/**
* Creates new ExceptionEventImpl.
Expand All @@ -60,6 +62,8 @@ public static ExceptionEventImpl read(MirrorImpl target,
event.readThreadAndLocation(target, dataInStream);
event.fException = ObjectReferenceImpl.readObjectRefWithTag(target,
dataInStream);
event.fException.disableCollection();
event.fExceptionCollectionEnabled = false;
event.fCatchLocation = LocationImpl.read(target, dataInStream);
return event;
}
Expand All @@ -79,4 +83,14 @@ public Location catchLocation() {
public ObjectReference exception() {
return fException;
}

/**
* Enables garbage collection for the exception in the event. GC for the exception is initially disabled, until the exception event is processed.
*/
public void enableExceptionGC() {
if (!fExceptionCollectionEnabled && fException != null) {
fException.enableCollection();
fExceptionCollectionEnabled = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.jdi.internal.event.ExceptionEventImpl;
import org.eclipse.jdt.debug.core.IJavaLineBreakpoint;
import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;

Expand Down Expand Up @@ -153,7 +154,13 @@ private void dispatch(EventSet eventSet) {
}
}
vote = true;
resume = listener.handleEvent(event, fTarget, !resume, eventSet) && resume;
try {
resume = listener.handleEvent(event, fTarget, !resume, eventSet) && resume;
} catch (Throwable t) {
logHandleEventError(listener, event, t);
} finally {
enableGCForExceptionEvent(event);
}
continue;
}

Expand Down Expand Up @@ -187,7 +194,13 @@ private void dispatch(EventSet eventSet) {
.get(event.request());
if (listener != null) {
vote = true;
resume = listener.handleEvent(event, fTarget, !resume, eventSet) && resume;
try {
resume = listener.handleEvent(event, fTarget, !resume, eventSet) && resume;
} catch (Throwable t) {
logHandleEventError(listener, event, t);
} finally {
enableGCForExceptionEvent(event);
}
continue;
}
}
Expand Down Expand Up @@ -411,4 +424,17 @@ private void fireEvents(EventSet set) {
}
}

private static void enableGCForExceptionEvent(Event event) {
if (event instanceof ExceptionEventImpl) {
try {
((ExceptionEventImpl) event).enableExceptionGC();
} catch (Throwable t) {
JDIDebugPlugin.logError("Failed to enable GC for event: " + event, t); //$NON-NLS-1$
}
}
}

private static void logHandleEventError(IJDIEventListener listener, Event event, Throwable t) {
JDIDebugPlugin.logError("Exception occurred while notifying listener: " + listener + ", with event: " + event, t); //$NON-NLS-1$ //$NON-NLS-2$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.ClasspathEntry;
import org.eclipse.jdt.internal.core.JavaProject;
import org.eclipse.jdt.internal.launching.CompositeId;
import org.eclipse.jdt.internal.launching.DefaultEntryResolver;
Expand Down Expand Up @@ -1036,12 +1037,7 @@ public static boolean isModule(IClasspathEntry entry, IJavaProject proj) {
return false;
}

for (IClasspathAttribute classpathAttribute : entry.getExtraAttributes()) {
if (classpathAttribute.getName().equals(IClasspathAttribute.MODULE) && "true".equals(classpathAttribute.getValue())) {//$NON-NLS-1$
return true;
}
}
return false;
return ClasspathEntry.isModular(entry);

}

Expand Down

0 comments on commit 890a4ee

Please sign in to comment.