From 0cd59bdc2bbf355f4546c8c9dfd4711414ddc7c6 Mon Sep 17 00:00:00 2001 From: wenyutang-ms Date: Mon, 30 Mar 2026 16:23:59 +0800 Subject: [PATCH] fix: handle NoSuchMethodError for isMainMethodCandidate() on older JDT Core Catch NoSuchMethodError when calling SourceMethod.isMainMethodCandidate() in ResolveMainClassHandler and ResolveMainMethodHandler. This method was added in JDT Core 3.36 and is unavailable on older versions, causing the debugger to fail entirely when resolving main classes. Fixes microsoft/vscode-java-debug#1598 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../debug/plugin/internal/ResolveMainClassHandler.java | 7 +++++++ .../plugin/internal/ResolveMainMethodHandler.java | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainClassHandler.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainClassHandler.java index fc818944..af9cdbc5 100644 --- a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainClassHandler.java +++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainClassHandler.java @@ -241,6 +241,13 @@ private boolean isMainMethod(IMethod method) { return method.isMainMethod(); } catch (JavaModelException e) { // do nothing + } catch (NoSuchMethodError e) { + // isMainMethodCandidate() was added in JDT Core 3.36, fall back to isMainMethod() + try { + return method.isMainMethod(); + } catch (JavaModelException ex) { + // do nothing + } } return false; 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 be1092bb..820bddd5 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 @@ -112,9 +112,13 @@ public static IMethod getMainMethod(IType type) throws JavaModelException { boolean allowInstanceMethod = isInstanceMainMethodSupported(type); List methods = new ArrayList<>(); for (IMethod method : type.getMethods()) { - if (method instanceof SourceMethod - && ((SourceMethod) method).isMainMethodCandidate()) { - methods.add(method); + try { + if (method instanceof SourceMethod + && ((SourceMethod) method).isMainMethodCandidate()) { + methods.add(method); + } + } catch (NoSuchMethodError e) { + // isMainMethodCandidate() was added in JDT Core 3.36, skip if unavailable } if (method.isMainMethod()) {