You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
While debugging Java, 'Cannot evaluate because of compilation error(s): Evaluations must contain either an expression or a block of well-formed statements' #1158
In a Maven project, creating a TableRowSorter breaks the Debug Console evaluator.
Set a breakpoint at the indicated line in the source file. At the breakpoint, type a simple expression (e.g. "before step") in the Debug Console. It works normally. Step the statement. Type an expression again and it fails.
Extension version: 0.40.1
VS Code version: Code 1.66.2 (dfd34e8260c270da74b5c2d86d61aee4b6d56977, 2022-04-11T07:46:01.075Z)
OS version: Windows_NT x64 10.0.19044
Restricted Mode: No
Source file (SlideCatalog.java, located in the src/main/java/SlideCatalog subfolder of .project's folder):
package SlideCatalog;
/*
* SlideCatalog.java requires no other files.
*/
import javax.swing.table.*;
public class SlideCatalog
{
public SlideCatalog() {
/*-->Set breakpoint here<--*/ TableRowSorter<MyTableModel> sorter = new TableRowSorter<>(null);
}
class MyTableModel extends AbstractTableModel {
public int getColumnCount() {
return 4;
}
public int getRowCount() {
return 4;
}
public String getColumnName(int col) {
return "";
}
public Object getValueAt(int row, int col) {
return "";
}
public Class<?> getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SlideCatalog();
}
});
}
}
Original comment has been updated with a screenshot. Before stepping the offending statement, the string literal "before step" evaluated properly. After stepping, the string literal "after step" didn't.
It might be possible to boil it down a bit further but my attempts failed so far.
So I think generics might have something to do with it as well.
Place a breakpoint on the last line (see the comment), from there you should be able to see (in the watch window!) tree_builder, builder, s and vscode_bugged.VSCode_Bugged_Example_3.tree_builder but none of them works.
This is not a maven project or the like, just VSCode_Bugged_Example_3.java being located in src/vscode_bugged.
In the 'variables' panel I can see this, user, and uuid all with their expected values, they also show as inlay hints in the editor, however when I open the debug console and try to access them (or to access imported classes which are used within the current method) I get the error message Evaluations must contain either an expression or a block of well-formed statements.
vscjava.vscode-java-debug v0.58.0
redhat.java v1.33.0
VSCode 1.92.0
MacOS 14.5
JDK (debugger and server) 14.0.2 (via https://cdn.azul.com/zulu/bin version zulu14.29.23-ca-jdk14.0.2-macosx_x64)
Tomcat v10.0.27
Gradle reports the following compiler args, maybe something is wrong here?
While we did occasionally experience this issue in Eclipse's debugger, it was only occasionally. The workaround was just to restart the server, but that doesn't seem to work here. It happens for any expression entered, interestingly it will correctly identify when a property/method doesn't exist before it prints the error message;
Other fixes to this issue in Eclipse I've found online include;
avoiding package/class name conflicts (eg don't use Foo.Foo)
we use verbose class and packages names (all packages are uk.co.* or com.*) so this isn't the issue
ensure all Jars are in the classpath
doing this doesn't change the debugger behaviour
These and other solutions for eclipse don't appear to be solutions for VSCode.
Interestingly the issue only seems to appear once I step over a few expressions, but all the methods I tested are just plain java code; method calls, variable declarations, a few literals, and in one case a typecast.
Hi peter rumsey (@prumseycsi), 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.
Issue: Debug Console evaluations fail with error:
Cannot evaluate because of compilation error(s): Evaluations must contain either an expression or a block of well-formed statements.
This occurs after stepping through code that uses generics/inner classes (e.g. TableRowSorter<MyTableModel> sorter = new TableRowSorter<>(null);).
Workarounds & Suggestions
Upgrade to the latest Java Debugger extension and VS Code; many evaluation bugs have been fixed in newer releases.
Try adding expressions as a watch instead of using the Debug Console.
Wrap complex expressions in a well-formed block, for example:
The 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!
Activity
testforstephen commentedon Apr 26, 2022
peter rumsey (@prumseycsi) Would you mind sharing a screenshot to show the snippet you evaluate and the error message you get? thanks.
prumseycsi commentedon Apr 26, 2022
Original comment has been updated with a screenshot. Before stepping the offending statement, the string literal "before step" evaluated properly. After stepping, the string literal "after step" didn't.
testforstephen commentedon Apr 27, 2022
Cannot reproduce it with JDK 11.
What JDK version you're using?

prumseycsi commentedon Apr 27, 2022
That'd be Adopt OpenJDK 11.0.10+9, the only version 11 JDK that VSCode would install for me at the time (March 2021).
clankill3r commentedon May 25, 2022
I have the same problem, also using OpenJDK, but I don't have a maven project.
I also upgraded to JavaSE-17 but it made no difference.
testforstephen commentedon May 26, 2022
Doeke Wartena (@clankill3r) Could you please provide more details about your case? It's better to provide the snippet and a sample project?
clankill3r commentedon May 26, 2022
Jinbo Wang (@testforstephen)
Ok, I boiled it down to this:
It might be possible to boil it down a bit further but my attempts failed so far.
So I think generics might have something to do with it as well.
Place a breakpoint on the last line (see the comment), from there you should be able to see (in the watch window!)
tree_builder,builder,sandvscode_bugged.VSCode_Bugged_Example_3.tree_builderbut none of them works.This is not a maven project or the like, just
VSCode_Bugged_Example_3.javabeing located insrc/vscode_bugged.testforstephen commentedon May 27, 2022
Doeke Wartena (@clankill3r) thanks for the snippet, I can reproduce it and it's a bug. I create a new issue to track your use case. #1169
WillsterJohnsonAtZenesis commentedon Aug 12, 2024
This is still an issue, I presume #1169 is too
In the 'variables' panel I can see
this,user, anduuidall with their expected values, they also show as inlay hints in the editor, however when I open the debug console and try to access them (or to access imported classes which are used within the current method) I get the error messageEvaluations must contain either an expression or a block of well-formed statements.vscjava.vscode-java-debug v0.58.0
redhat.java v1.33.0
VSCode 1.92.0
MacOS 14.5
JDK (debugger and server) 14.0.2 (via
https://cdn.azul.com/zulu/binversionzulu14.29.23-ca-jdk14.0.2-macosx_x64)Tomcat v10.0.27
Gradle reports the following compiler args, maybe something is wrong here?
While we did occasionally experience this issue in Eclipse's debugger, it was only occasionally. The workaround was just to restart the server, but that doesn't seem to work here. It happens for any expression entered, interestingly it will correctly identify when a property/method doesn't exist before it prints the error message;
Other fixes to this issue in Eclipse I've found online include;
Foo.Foo)uk.co.*orcom.*) so this isn't the issueThese and other solutions for eclipse don't appear to be solutions for VSCode.
Interestingly the issue only seems to appear once I step over a few expressions, but all the methods I tested are just plain java code; method calls, variable declarations, a few literals, and in one case a typecast.
Jinbo Wang (@testforstephen) is there any plan to resolve this?
WillsterJohnsonAtZenesis commentedon Aug 14, 2024
As an experiment I've upgraded to Java 22 with the below gradle config and
22.0.2-zulufrom sdkman!'s list.The issue persists, though it seems that it's a little better in some circumstances (this may be entirely subjective).
github-actions commentedon Nov 11, 2025
Hi peter rumsey (@prumseycsi), 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.
Issue: Debug Console evaluations fail with error:
This occurs after stepping through code that uses generics/inner classes (e.g.
TableRowSorter<MyTableModel> sorter = new TableRowSorter<>(null);).Workarounds & Suggestions
References
Other references with low confidence
The 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!
robertonav20 commentedon Nov 21, 2025
Hi Jinbo Wang (@testforstephen)
this issue still persists on latest version within debugging sessions is very annoying.
Have you some updates?