eclipse-jdt / eclipse.jdt.debug

Eclipse Public License 2.0
16 stars 46 forks source link

All evaluations in Debug Shell fail with "ClassNotFoundException" #295

Closed davidmichaelkarr closed 1 year ago

davidmichaelkarr commented 1 year ago

Using Eclipse 2023-06.

Any expression that I highlight in the Debug Shell and select "Display" fails with:

Evaluation failed. Reason(s):
    An exception occurred: java.lang.ClassNotFoundException

The expression doesn't have to be complicated at all. I tried simply "1". Same result. I looked in the Eclipse log, and there is nothing coinciding with this.

I'm testing this while sitting at a breakpoint while debugging an application. I've tried this many times, with many expressions, and they all fail in the same way.

jjohnstn commented 1 year ago

I tried a simple test on my current Eclipse which is 2023-09 M3. Using the following test:

package tests;

public class TestDebug {

    public void foo() {
        int a = 4 * 6;
        System.out.println(a);
        System.out.println(a + 4);
    }

    public static void main(String[] args) {
        TestDebug x = new TestDebug();
        x.foo();
    }

}

I had a breakpoint set at the first println in foo(). I then had the following in my Debug Console:

System.out.println(a);
Integer.compare(a, 4);
1

Highlighting each line separately and doing right-click Display, all 3 lines work. The println ends up printing to the Console, the compare ends up printing (int)1 in the console as does selecting 1 and doing Display.

Does this simple test work for you? If yes, can you provide details on your particular test class?

davidmichaelkarr commented 1 year ago

I have no particular test class. I see this for every application I attempt to debug. I will set up this sample as a project and test that.

iloveeclipse commented 1 year ago

Either installation or workspace must be corrupted in some way. Start with clean install and a new workspace. Create trivial new Java project and snippet like above. Make sure you can run and debug it. Try displaying values like above. If that doesn't work, check error log. There must be something.

davidmichaelkarr commented 1 year ago

That test case has no problem. It happens with my applications, which are all much larger than this sample. As I said, there is nothing in the error log.

SarikaSinha commented 1 year ago

Instead of using Debug Shell, Can you try using Expression View or simple Inspect after hitting at the breakpoint? This is just to make sure all the buildpath have been set properly.

davidmichaelkarr commented 1 year ago

Ok, good idea. I also thought it would be useful to set a breakpoint at the first line of the main method. That got some curious results. At that point, I entered "args" in the Debug Shell, selected it, and executed "Display". That time, instead of just printing ClassNotFoundException in the debug shell, it actually hit a breakpoint at the point where it was throwing the CNFE, which had some useful information. The following is a picture that shows some useful things:

image

Note that I have "cn" selected in the Variables view, and nothing is shown in the bottom box, even though the right side clearly shows it is a string value, showing the name of a Groovy class.

You'll also see that I was hovering over the "cn" expression in the code, and that also shows the class name, and no value is shown in the bottom box. The class name appears to be "org.codehaus.groovy.runtime.ScriptBytecodeAdapter". Note that I found no way to copy that string to the clipboard from either the Variables view or the expression view. It never showed the value in the bottom box, and there wasn't any way to select it.

As this hit the breakpoint where it was throwing the CNFE, here is the stacktrace for it:

Thread [main] (Suspended (uncaught exception ClassNotFoundException))   
    ClassLoaders$AppClassLoader(BuiltinClassLoader).loadClass(String, boolean) line: 581    
    ClassLoaders$AppClassLoader.loadClass(String, boolean) line: 178    
    ClassLoaders$AppClassLoader(ClassLoader).loadClass(String) line: 521    
    Class<T>.forName0(String, boolean, ClassLoader, Class<?>) line: not available [native method]   
    Class<T>.forName(String) line: 315  
    Application.main(String[]) line: 56 

I have no idea whether that class is significant. I do have the groovy-eclipse plugin installed. Is this a problem with that plugin?

iloveeclipse commented 1 year ago

Is advanced source lookup enabled or not? image

Can you attach your debug launch config, or play with that and check if the expected libraries are on debugger source lookup list?

davidmichaelkarr commented 1 year ago

Yes, advanced source lookup is turned on. Should I try turning it off?

Do you mean take screenshots of every tab of the launch config?

This is a maven application. It has all of the maven dependencies. It has the "Maven Dependencies" specified in the classpath as expected.

davidmichaelkarr commented 1 year ago

However, this did give me a clue to explore. I recently had to make a change to the configuration of the groovy-eclipse plugin, which often causes problems for me, changing from Groovy 3 to Groovy 4. However, I see that some of our artifacts depend on Groovy 3. I have no idea why this would cause all debug shell evaluations to fail, but it seems like it might be related. I'm going to try changing the config back to Groovy 3, which will result in me having to reset many project configs and recompile everything. In a few hours I'll be able to see if this made any difference.

davidmichaelkarr commented 1 year ago

Ok, that led to the solution. I also asked about this problem on the groovy-eclipse github, and they pointed me to this: https://github.com/groovy/groovy-eclipse/wiki/5.0.0-Release-Notes#debug-support . I added that flag setting to the eclipse.ini, and I also backed up from Groovy 4 to Groovy 3. I think it was probably the former that fixed this, but I guess I will move Groovy back to version 4 to confirm that.

jjohnstn commented 1 year ago

Closing