False positive "Flexible Constructor Bodies is only available with source level 25 and above" with Lombok @RequiredArgsConstructor on Java 21
Description
I am seeing a false-positive Java compiler diagnostic in VS Code when using Lombok @RequiredArgsConstructor in a Java 21 Maven project.
The project compiles and installs successfully with Maven, but VS Code reports:
The Java feature 'Flexible Constructor Bodies' is only available with source level 25 and above
The source code itself does not use Flexible Constructor Bodies or any Java 25 syntax.
Environment
- VS Code Java extension:
[email protected](pre-release) - Project source level: Java 21
- Build system: Maven
- Lombok: used through Maven dependency / annotation processing
mvn install: SUCCESS
Minimal reproducer
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public class Test {
private final String value;
}
Maven configuration:
<properties>
<maven.compiler.release>21</maven.compiler.release>
</properties>
Steps to reproduce
- Create a Maven project targeting Java 21.
- Add Lombok.
- Create a class containing a
finalfield. - Add Lombok
@RequiredArgsConstructor. - Open the project in VS Code with
[email protected]. - Let the Java Language Server finish importing and analysing the project.
Actual behavior
VS Code reports:
The Java feature 'Flexible Constructor Bodies' is only available with source level 25 and above
even though the source code does not contain a constructor using Flexible Constructor Bodies.
The error appears to be related to the constructor generated by Lombok.
Expected behavior
No Java 25 / Flexible Constructor Bodies diagnostic should be reported.
The generated constructor is equivalent to ordinary Java 21-compatible code:
public Test(String value) {
this.value = value;
}
Maven result
The project builds successfully:
mvn install
BUILD SUCCESS
Therefore the issue appears to be limited to VS Code / JDT Language Server diagnostics rather than the Maven compiler configuration.
Additional information
The same issue occurs in a real Spring project using:
@RequiredArgsConstructor
public class ProdCatalog {
private final DoubleThrower<RestFunctionsException, RuntimeException> thrower;
private final NamedParameterJdbcTemplate jdbc;
}
There is no explicit constructor in the class.
The diagnostic is therefore likely triggered during Lombok/JDT AST processing of the generated required-arguments constructor.
I am using the 1.57 pre-release because of a separate issue present in 1.56.0, so reverting to 1.56.0 is not currently a practical workaround.
Please let me know if a Java Language Server log, Lombok version, complete pom.xml, or a minimal reproducer repository would be useful.
... You should still be able to work on projects as old as Java 8 with vscode-java. ... There's not much we can do on our end to address this until this is fixed upstream lombok. Lombok has been fairly slow to adopt to the latest release of Eclipse's internal compiler, so this might take a while.
Got it, thx.
23. > Well, the specific error seems to affect both java versions. The version limitation in 1.57 is then strange coincidence :) But still a problem for a lot of projects in itself.
jdtls, the language server that powers vscode-java's features, requires Java 25 to run as of the latest version. vscode-java bundles a copy of the JRE it needs to run jdtls (i.e. 1.57.0 bundles a copy of Java 25), so you shouldn't need to install it yourself for the extension to work. You should still be able to work on projects as old as Java 8 with vscode-java. My understanding is that the problems being reported here are caused by lombok; lombok doesn't support the latest version of Eclipse's internal compiler, which this extension makes use of. I think downgrading to 1.56.0 is the best path forward if you're working with lombok. There's not much we can do on our end to address this until this is fixed upstream lombok. Lombok has been fairly slow to adopt to the latest release of Eclipse's internal compiler, so this might take a while.
There has been some progress upstream: eclipse-jdt/eclipse.jdt.core#5489 identified the underlying Lombok/ECJ compatibility issue, and a backward-compatibility fix has already been merged in PR #5490. While Lombok is also working on adapting to the new ECJ AST structure, upgrading Lombok may not be feasible for projects with pinned dependencies. Currently, we having to downgrade vscode-java to 1.56.0 as a workaround. Could the next vscode-java release include a JDT Core/ECJ build containing this compatibility fix? This would help restore compatibility with existing Lombok versions without requiring changes to project dependencies.
I can confirm this issue with redhat.java 1.57.0 on Java 17 and Lombok 1.18.36. In our case the problem is more severe than an incorrect diagnostic: the Eclipse/JDT compilation performed by VS Code actually produces an invalid .class file for a Lombok-generated builder.
We get:
java.lang.ClassFormatError: Invalid method Code length 0 in class file
nl/rivm/dvp/rvp/machine/model/ComponentPlanning$ComponentPlanningBuilder
Inspecting the generated class with javap -v shows that with redhat.java 1.57.0 the Lombok-generated constructor has an empty Code attribute:
ComponentPlanning$ComponentPlanningBuilder();
descriptor: ()V
flags: (0x0000)
RuntimeInvisibleAnnotations:
0: #8()
lombok.Generated
Code:
stack=0, locals=1, args_size=1
LocalVariableTable:
Start Length Slot Name Signature
0 0 0 this Lnl/rivm/dvp/rvp/machine/model/ComponentPlanning$ComponentPlanningBuilder;
We isolated this from Maven compilation. After deleting the generated builder .class, merely touching ComponentPlanning.java while VS Code is running causes the Java language server to regenerate the invalid class.
Downgrading only redhat.java from 1.57.0 to 1.56.0 and repeating exactly the same test produces valid bytecode:
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #14 // Method java/lang/Object."<init>":()V
4: return
After the downgrade, the ClassFormatError disappears and the affected Cucumber tests run normally from VS Code Testing.
Environment:
Java: 17
Lombok: 1.18.36
vscode-java: 1.57.0 (broken)
vscode-java: 1.56.0 (works)
So this issue can affect not only editor diagnostics, but also the bytecode emitted by the incremental Eclipse/JDT compilation.
It seems the problem is fixed in VSCode Extension version 1.58.2026101408
When will this version be released?
I have run into the same issue. Using version 1.56.0 can resolve this problem.
Same here, I can confirm version 1.56.0 fixes the issue.
20. It seems the problem is fixed in VSCode Extension version 1.58.2026101408
Is there an estimated release date for this version?
Just manually installed newly released 1.58.0 in VS Code (the auto-update has 12 hours cooldown) and the issue is gone 👍
Closing this, since 1.58.0 should be released as of this morning, and it should fix the issue.
Works, thank you. EDIT: I updated the plugin without having to download anything manually of course.
After upgrading to the 1.58 pre-release version, adding the following setting resolved the Java Language Server startup issue:
// Disable AppCDS to prevent the Java Language Server from failing to start
"java.jdt.ls.appcds.enabled": "off"
Once the stable version of 1.58 is released, this workaround may no longer be necessary and the setting might be removable.