Repository navigation
References to launch.json in error messaging may be misleading #431
Description
Activity
I would guess, such users would see the debug session launch just fine, but the moment they try to hover over an expression or perform some evaluation they would see :
!ENTRY java-debug 4 0 2025-04-09 11:32:04.911 !MESSAGE [error response][evaluate]: Cannot evaluate because of java.lang.IllegalStateException: Cannot evaluate, please specify projectName in launch.json.. !STACK 0 com.microsoft.java.debug.core.DebugException: Cannot evaluate because of java.lang.IllegalStateException: Cannot evaluate, please specify projectName in launch.json.. at com.microsoft.java.debug.core.adapter.AdapterUtils.createCompletionException(AdapterUtils.java:266) at com.microsoft.java.debug.core.adapter.handler.EvaluateRequestHandler.lambda$handle$0(EvaluateRequestHandler.java:180) at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source) at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(Unknown Source) at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source) at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source) at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source) at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source) at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) Caused by: java.lang.IllegalStateException: Cannot evaluate, please specify projectName in launch.json. at com.microsoft.java.debug.plugin.internal.eval.JdtEvaluationProvider.findJavaProjectByType(JdtEvaluationProvider.java:299) at com.microsoft.java.debug.plugin.internal.eval.JdtEvaluationProvider.ensureDebugTarget(JdtEvaluationProvider.java:419) at com.microsoft.java.debug.plugin.internal.eval.JdtEvaluationProvider.evaluate(JdtEvaluationProvider.java:141) at com.microsoft.java.debug.plugin.internal.eval.JdtEvaluationProvider.evaluate(JdtEvaluationProvider.java:116) at com.microsoft.java.debug.core.adapter.handler.EvaluateRequestHandler.lambda$handle$0(EvaluateRequestHandler.java:90) ... 7 moreI guess the real issue is one of documentation/visibility. It's mentioned at https://github.com/microsoft/vscode-java-debug?tab=readme-ov-file#attach :
projectName - The preferred project in which the debugger searches for classes. There could be duplicated class names in different projects. It is required when the workspace has multiple java projects, otherwise the expression evaluation and conditional breakpoint may not work.
Update: I mean there's an easy workaround (specify
projectName). However it seems it's only a problem when there are multiple projects in the workspace. If I'm understanding it correctly, what stops the logic from just choosing any project for the sake of avoiding completely broken evaluation.Hi Rob Stryker (@robstryker), I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.
Suggestions
• When invoking vscode.debug.startDebugging programmatically, pass an explicit workspace folder or project name so the Java debugger won’t fall back to a misleading “launch.json” error:
const folder = vscode.workspace.workspaceFolders![0]; await vscode.debug.startDebugging(folder, { type: 'java', request: 'attach', name: 'Debug (Remote)', hostName: 'localhost', port, projectName: folder.name });
• As a long-term fix, consider updating the Java Debug extension to remove hard-coded “launch.json” references in its error messages and point instead to the adapter’s configuration API.
Further reading
• VS Code Java Debugging docs – how to configure launch.json or debug configurations programmatically
https://code.visualstudio.com/docs/java/java-debuggingOther references with low confidence
• Can’t auto generating java launch configuration in launch.json file – NullPointerException when no launch.json exists (similar missing-config symptom)
microsoft/vscode-java-debug#132The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!
https://github.com/microsoft/java-debug/search?q=launch.json
There appear to be only two references to launch.json in this repository. There does not appear to be any part of the code actually reading or referencing or introspecting a file named launch.json.
End users may find references to launch.json confusing if a third party tool has launched the debugger to connect to a java process and did not pass in a "projectName" to the call. While I realize this is a bit outside the scope of this repository, an example would be a vscode extension using the vscode.debug API (which flows to the https://github.com/microsoft/vscode-java-debug extension) and not setting a project name. In this case there is no launch.json file.
Since this repository itself does not read a launch.json at all, and all configuration is passed in via a Debug Adapter, not an existing file, these references to a file name are very misleading.