diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugDelegateCommandHandler.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugDelegateCommandHandler.java index 5db924442..d3d2bf835 100644 --- a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugDelegateCommandHandler.java +++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugDelegateCommandHandler.java @@ -70,7 +70,7 @@ public Object executeCommand(String commandId, List arguments, IProgress case VALIDATE_LAUNCHCONFIG: return new ResolveMainClassHandler().validateLaunchConfig(arguments); case RESOLVE_MAINMETHOD: - return ResolveMainMethodHandler.resolveMainMethods(arguments); + return ResolveMainMethodHandler.resolveMainMethods(arguments, progress); case INFER_LAUNCH_COMMAND_LENGTH: return LaunchCommandHandler.getLaunchCommandLength(JsonUtils.fromJson((String) arguments.get(0), LaunchArguments.class)); case CHECK_PROJECT_SETTINGS: diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainMethodHandler.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainMethodHandler.java index aaef587c3..85ff58978 100644 --- a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainMethodHandler.java +++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainMethodHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018 Microsoft Corporation and others. + * Copyright (c) 2018-2020 Microsoft Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -18,7 +18,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jdt.core.Flags; @@ -42,8 +42,8 @@ public class ResolveMainMethodHandler { * Resolve the main methods from the current file. * @return an array of main methods. */ - public static Object resolveMainMethods(List arguments) throws DebugException { - if (arguments == null || arguments.isEmpty()) { + public static Object resolveMainMethods(List arguments, IProgressMonitor monitor) throws DebugException { + if (monitor.isCanceled() || arguments == null || arguments.isEmpty()) { return Collections.emptyList(); } @@ -51,16 +51,20 @@ public static Object resolveMainMethods(List arguments) throws DebugExce // trigger a background job to update the change to the CompilationUnit. Because of race condition, the resolveMainMethods may read // an old CompilationUnit. So add some waiting logic to wait the Document Update to finish first. try { - Job.getJobManager().join(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, new NullProgressMonitor()); - } catch (OperationCanceledException ignorable) { - // Do nothing. + Job.getJobManager().join(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, monitor); + } catch (OperationCanceledException e) { + return Collections.emptyList(); } catch (InterruptedException e) { // Do nothing. } + if (monitor.isCanceled()) { + return Collections.emptyList(); + } + String uri = (String) arguments.get(0); final ICompilationUnit unit = JDTUtils.resolveCompilationUnit(uri); - if (unit == null || unit.getResource() == null || !unit.getResource().exists()) { + if (monitor.isCanceled() || unit == null || unit.getResource() == null || !unit.getResource().exists()) { return Collections.emptyList(); }