projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.83k stars 2.37k forks source link

[BUG] Lombok throws ArrayIndexOutOfBoundsException Exception when run with Gradle and JDK 14 #2539

Open MariusBrill opened 4 years ago

MariusBrill commented 4 years ago

Describe the bug Whenever i run a gradle task with lombok 1.18.12, gradle 6.5 and JDK 14 the ArrayIndexOutOfBoundsException you see in the exception.txt provided occurs. The error does not occur with lombok 1.18.12, gradle 6.5 and JDK 13.

To Reproduce Create a project with a class using the Builder and Builder.Default annotations. Try to run gradlew build with gradle version 6.5, lombok version 1.18.12 and JDK 14.

Expected behavior Lombok should not run into an exception during the building process.

Version info (please complete the following information):

Rawi01 commented 4 years ago

I just compiled a project using lombok 1.18.12, gradle 6.5.1 and Java 14 (AdoptOpenJDK 14.0.2/OpenJDK 14.0.2) without any problems. Which java version do you use? Can you share a simple sample project?

MariusBrill commented 4 years ago

Hi @Rawi01 , i just created a small git repo which makes the bug occur: https://github.com/mbrill-nt/lombok_throws_an_exception_with_me i hope that helps. If you run gradlew clean build the exception should occur.

The issue appears to be linked to the NotBlank-Annotation i used from javax.validation in line 13 of MyClass. Just to be sure, here my gradlew -version output:


Gradle 6.5

Build time: 2020-06-02 20:46:21 UTC Revision: a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4

Kotlin: 1.3.72 Groovy: 2.5.11 Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019 JVM: 14.0.2 (Oracle Corporation 14.0.2+12-46) OS: Windows 10 10.0 amd64

Rawi01 commented 4 years ago

Thanks for the example project, can confirm that it doesn't work.

karuppiah7890 commented 4 years ago

If no one is working on this, I would like to give it a try. I'm a complete newbie, just trying to see if I can do this. I will revert back if I get stuck or if I can't do it, so that others can do it! :)

Rawi01 commented 4 years ago

I already spend some time on this one, it is not as easy as it seems... I figured out that:

Rawi01 commented 4 years ago

Created a PR for the first bug. I also uploaded a branch that contains the potential fix I mentioned before (https://github.com/Rawi01/lombok/tree/jcexpression-pos) but as long as there are no test cases for it I don't think that it is ready to be merged.

rzwitserloot commented 3 years ago

Does current edge solve this issue? It includes @Rawi01 's fix.

Rawi01 commented 3 years ago

@rzwitserloot I only fixed the misleading error message but the problem is still not solved. I linked a branch that, at least during my limited tests, solved the issue but I was unable to create a real unit test.

mjustin commented 3 years ago

My linked duplicate (#2728) has a minimal test case/reproduction steps using just javac and the core Java libraries, in case that's helpful for testing or implementing the solution.

Test.java

import lombok.Builder;

import java.lang.annotation.*;
import java.util.List;

@Builder
public class Test {
    @Builder.Default
    private final List<@NotNull String> problematicProperty = List.of("A", "B", "C");

    @Target({ElementType.TYPE_USE})
    @Retention(RetentionPolicy.RUNTIME)
    public @interface NotNull { }
}

Test command/output

$ curl -s https://repo1.maven.org/maven2/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar -O

$ javac -cp lombok-1.18.16.jar Test.java
An exception has occurred in the compiler (14.0.2). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
    at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writePosition(ClassWriter.java:671)
    at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeTypeAnnotation(ClassWriter.java:648)
    at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeTypeAnnotations(ClassWriter.java:552)
    at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeCode(ClassWriter.java:1104)
    at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeMethod(ClassWriter.java:972)
    at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeMethods(ClassWriter.java:1463)
    at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeClassFile(ClassWriter.java:1568)
    at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeClass(ClassWriter.java:1489)
    at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:757)
    at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1646)
    at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1614)
    at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:972)
    at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:316)
    at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
    at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
    at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)
printing javac parameters to: /path/to/javac.20210127_121326.args