vscode-java-debug
vscode-java-debug copied to clipboard
can't refer to java.lang static methods in expression
Add breakpoint in a constructor (such as NoSuchMethodError) with this log expression:
new StringBuilder().append(s).append("->").append(java.util.Arrays.stream(Thread.currentThread().getStackTrace()).map(StackTraceElement::toString).collect(java.util.stream.Collectors.joining("\n"))).toString()
This works in intellij but in vscode I get:
[Logpoint] Log message '{new StringBuilder().append(s).append("->").append(java.util.Arrays.stream(Thread.currentThread().getStackTrace()).map(StackTraceElement::toString).collect(java.util.stream.Collectors.joining("\n"))).toString()}' error: Cannot evaluate because of compilation error(s): [The package java.lang collides with a type, The package java.lang conflicts with a package accessible from another module: java.base].
When works it should print the message + stacktrace.
I expect the error has something to do with the static java.lang.Thread implicit reference for Thread.currentThread() call. I also added explicit java.lang.Thread but same error.
Environment
- Operating System: osx
- JDK version: temurin java 21
- Visual Studio Code version: 1.84.2
- Java extension version: "v1.25.1"
- Java Debugger extension version: "v0.55.0"
Instead of using a logpoint, can you try to evaluate the same snippet in the DEBUG CONSOLE when the breakpoint is hit?
Instead of using a logpoint, can you try to evaluate the same snippet in the DEBUG CONSOLE when the breakpoint is hit?
I have tried this and it is the same. This issue is an upstream jdt.debug issue. jdt.debug creates the following class
package java.lang;
public class NoSuchMethodError extends IncompatibleClassChangeError{
void ___run(java.lang.String s) throws Throwable {
return new StringBuilder().append(s).append("->").append(java.util.Arrays.stream(Thread.currentThread().getStackTrace()).map(StackTraceElement::toString).collect(java.util.stream.Collectors.joining("\n"))).toString();
}
private static final long serialVersionUID;
public NoSuchMethodError (){
}
public NoSuchMethodError (String s){
}
}
and throws The package java.lang collides with a type, The package java.lang conflicts with a package accessible from another module: java.base