redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.05k stars 420 forks source link

Preview features enabled at an invalid source release level 21, preview can be enabled only at source level 22 #3658

Closed aghasemi closed 1 month ago

aghasemi commented 1 month ago

Hello,

I have Java 21 installed on my machine. I have a maven project for which preview features are enabled (<compilerArgs>--enable-previev</compilerArgs> in the configuration of the compiler plugin).

Previously it worked fine, but now if I try to run a main method in the prject by clicking the play button in the UI (or Run that appears above the method signature), I get the error Preview features enabled at an invalid source release level 21, preview can be enabled only at source level 22 from the VSCode. The error does not happen when I run maven from the terminal (mvn compile).

Explicitly specifying the runtime in the VSCode settings did not solve the issue. Is there anything else I can do?

Thanks

Environment
Steps To Reproduce
  1. Have a maven project with preview features enabled and source version set to 21
  2. Try to run a main() method from the UI.
Current Result

Error Preview features enabled at an invalid source release level 21, preview can be enabled only at source level 22.

Expected Result

Project should build and run as Java 21 is installed on the system

Additional Informations
fbricon commented 1 month ago

It's a known limitation of the upstream compiler used under the hood. See https://github.com/redhat-developer/vscode-java/wiki/Enabling-Java-preview-features for more details.

This is not something we can fix unfortunately.

aghasemi commented 1 month ago

Thank you for the link. Regarding the implication does it mean that at any point in time, only previewe features of the latest JDK are supported, no matter how I set my runtimes etc.. (wasn't clear in the link).

And, is there a way to find out what was the latest extension version which had ECJ 21 instead of 22?

It's a known limitation of the upstream compiler used under the hood. See https://github.com/redhat-developer/vscode-java/wiki/Enabling-Java-preview-features for more details.

This is not something we can fix unfortunately.