Skip to content

Commit 0cd59bd

Browse files
wenytang-msCopilot
andcommitted
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>
1 parent b35f033 commit 0cd59bd

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainClassHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ private boolean isMainMethod(IMethod method) {
241241
return method.isMainMethod();
242242
} catch (JavaModelException e) {
243243
// do nothing
244+
} catch (NoSuchMethodError e) {
245+
// isMainMethodCandidate() was added in JDT Core 3.36, fall back to isMainMethod()
246+
try {
247+
return method.isMainMethod();
248+
} catch (JavaModelException ex) {
249+
// do nothing
250+
}
244251
}
245252

246253
return false;

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainMethodHandler.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ public static IMethod getMainMethod(IType type) throws JavaModelException {
112112
boolean allowInstanceMethod = isInstanceMainMethodSupported(type);
113113
List<IMethod> methods = new ArrayList<>();
114114
for (IMethod method : type.getMethods()) {
115-
if (method instanceof SourceMethod
116-
&& ((SourceMethod) method).isMainMethodCandidate()) {
117-
methods.add(method);
115+
try {
116+
if (method instanceof SourceMethod
117+
&& ((SourceMethod) method).isMainMethodCandidate()) {
118+
methods.add(method);
119+
}
120+
} catch (NoSuchMethodError e) {
121+
// isMainMethodCandidate() was added in JDT Core 3.36, skip if unavailable
118122
}
119123

120124
if (method.isMainMethod()) {

0 commit comments

Comments
 (0)