vscode-java-debug icon indicating copy to clipboard operation
vscode-java-debug copied to clipboard

While debugging Java, 'Cannot evaluate because of compilation error(s): Evaluations must contain either an expression or a block of well-formed statements'

Open prumseycsi opened this issue 3 years ago • 10 comments

Issue Type: Bug

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.

#1158

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

Extensions (16)
Extension Author (truncated) Version
csharp ms- 1.24.4
python ms- 2022.4.1
vscode-pylance ms- 2022.4.2
jupyter ms- 2022.3.1000901801
jupyter-keymap ms- 1.0.0
jupyter-renderers ms- 1.0.6
remote-wsl ms- 0.66.0
cpptools ms- 1.9.8
java red 1.5.0
vscodeintellicode Vis 1.2.20
vscode-java-debug vsc 0.40.1
vscode-java-dependency vsc 0.19.1
vscode-java-pack vsc 0.22.4
vscode-java-test vsc 0.34.2
vscode-maven vsc 0.35.1
omnipascal Wos 0.19.0

.project file:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>SlideCatalog</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<buildCommand>
			<name>org.eclipse.m2e.core.maven2Builder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.jdt.core.javanature</nature>
		<nature>org.eclipse.m2e.core.maven2Nature</nature>
	</natures>
	<filteredResources>
		<filter>
			<id>1616719244136</id>
			<name></name>
			<type>30</type>
			<matcher>
				<id>org.eclipse.core.resources.regexFilterMatcher</id>
				<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
			</matcher>
		</filter>
	</filteredResources>
</projectDescription>

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();
            }
        });
    }
}

prumseycsi avatar Apr 26 '22 02:04 prumseycsi

@prumseycsi Would you mind sharing a screenshot to show the snippet you evaluate and the error message you get? thanks.

testforstephen avatar Apr 26 '22 09:04 testforstephen

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.

prumseycsi avatar Apr 26 '22 23:04 prumseycsi

Cannot reproduce it with JDK 11.

image

What JDK version you're using? image

testforstephen avatar Apr 27 '22 03:04 testforstephen

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).

prumseycsi avatar Apr 27 '22 20:04 prumseycsi

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.

clankill3r avatar May 25 '22 16:05 clankill3r

@clankill3r Could you please provide more details about your case? It's better to provide the snippet and a sample project?

testforstephen avatar May 26 '22 01:05 testforstephen

@testforstephen

Ok, I boiled it down to this:

package vscode_bugged;

public class VSCode_Bugged_Example_3 {

    
public static void main(String[] args) {
    foo(tree_builder);
}


static public class Node<T extends Node<T>> {
    public T parent;
}

static public class Tree_Builder<T extends Node<T>> {
    public T current;
}

static public class Element extends Node<Element> {
    public String name;
}

static public Tree_Builder<Element> tree_builder = new Tree_Builder<>();



static public <T extends Node<T>> void foo(Tree_Builder<T> builder) {
    String s = "nope";
    if (builder.current != null) {

    }
    System.out.println(s); // breakpoint here
}

}

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.

clankill3r avatar May 26 '22 09:05 clankill3r

@clankill3r thanks for the snippet, I can reproduce it and it's a bug. I create a new issue to track your use case. https://github.com/microsoft/vscode-java-debug/issues/1169

testforstephen avatar May 27 '22 08:05 testforstephen