lombok-intellij-plugin
lombok-intellij-plugin copied to clipboard
Intellij Delombok does not generate correct delombok'd code.
Describe the bug Using Intellij and the lombok plugin version 203.5981.41, when I delombok to see what code is generated I do not get the AtomicReference the lombok GetterLazy docs suggest:
@Getter(lazy=true)
private final double[] cached = expensive();
private double[] expensive() {
double[] result = new double[1000000];
for (int i = 0; i < result.length; i++) {
result[i] = Math.asin(i);
}
return result;
}
Generates this in Intellij:
private final double[] cached = expensive();
private double[] expensive() {
double[] result = new double[1000000];
for (int i = 0; i < result.length; i++) {
result[i] = Math.asin(i);
}
return result;
}
Not this as the docs suggest:
private final java.util.concurrent.AtomicReference<java.lang.Object> cached = new java.util.concurrent.AtomicReference<java.lang.Object>();
public double[] getCached() {
java.lang.Object value = this.cached.get();
if (value == null) {
synchronized(this.cached) {
value = this.cached.get();
if (value == null) {
final double[] actualValue = expensive();
value = actualValue == null ? this.cached : actualValue;
this.cached.set(value);
}
}
}
return (double[])(value == this.cached ? null : value);
}
private double[] expensive() {
double[] result = new double[1000000];
for (int i = 0; i < result.length; i++) {
result[i] = Math.asin(i);
}
return result;
}
Clearly, this is not lazy and so is of limited use, is this a change in how lombok works for lazy getters. Having investoigated the Intellij Lombok plugin and maven plugin , this is clearly an issue with the Intellij plugin. I initially raised this issue with lombok, see: https://github.com/rzwitserloot/lombok/issues/2661, but its clear the issue is in the Intellij plugin.
To Reproduce Delombok the code as shown on the lombok GetterLazy docs page and copied above in the description, either using the latest Intellij lombok plugin or the latest gradle lombok plugin.
Expected behavior Expected a lazy local AtomicReference. The generated code does not lazy instantiate the variable.
Version info (please complete the following information):
Lombok version. 1.18.16.
Gradle plugin. 5.3.0
Intellij plugin. 203.5981.41
Platform.
java 11.0.8 2020-07-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.8+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.8+10-LTS, mixed mode)
IntelliJ IDEA 2020.3 Beta (Ultimate Edition) Build #IU-203.5981.41, built on November 19, 2020 IntelliJ IDEA EAP User Runtime version: 11.0.9+11-b1145.15 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 10 10.0 GC: ParNew, ConcurrentMarkSweep Memory: 4029M Cores: 8 Registry: compiler.automake.allow.when.app.running=true Non-Bundled Plugins: org.intellij.plugins.hcl, CheckStyle-IDEA, Dart, Pythonid
Gradle 6.7.1 Additional context