Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I keep getting "Evaluations must contain either an expression or a block of well-formed statements"?

In my code, I am trying to output the value of src in the expressions window.

public void doIt() {
    String src = "test";
    System.out.println(src);
}

In Eclipse. I set a breakpoint on a line 3, and I open the "Expressions" window.

I add an expression src to evaluate, and I get Evaluations must contain either an expression or a block of well-formed statements

I've used the Expressions features... COUNTLESS times in my years of Java debugging.. Why does this happen now?

I've just recently started using Eclipse Juno.. vs Indigo. Did they change the way Expressions work?

like image 400
ddavison Avatar asked Jun 25 '13 19:06

ddavison


Video Answer


2 Answers

If your code use any generics, you may want to check this bug:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=341232

Occurs in all version of Eclipse up to 4.2. In short certain generics expressions cause Eclipse to completely fail on any evaluation (please see this example: https://bugs.eclipse.org/bugs/attachment.cgi?id=224760). Not sure whether your code uses any generics, but if so, this may be it. Note that it is enough to have one of the troublesome generics somewhere in your class, not necessary in your method.

like image 93
user2087898 Avatar answered Oct 03 '22 21:10

user2087898


I just spent TONS of time to figure out that if you will create a package "Foo" and inside this package you'll create class called "Foo", like this:

package Foo;

public class Foo{
    public Foo () {};
}

After the point when you use this class first time in your program, you will not be able to use expressions anymore:

import Foo.Foo; //this is the devil i think

public static void main(String[] args){
    EventQueue.invokeLater(new Runnable(){
        public void run(){
            //debug expressions works fine
            Foo tmp = new Foo();
            //debug expressions wouldn't work anymore
        }
    });
}

This bug can be reprodused up to current Eclipse Neon 4.7.

like image 23
mad_lobster Avatar answered Oct 03 '22 19:10

mad_lobster