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

Created on 5 Aug 2020  路  9Comments  路  Source: projectlombok/lombok

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):

  • Lombok version: 1.18.12
  • JDK 14
  • Gradle 6.5
  • Intellij IDEA Community 2019.2
awaiting-fix-confirmation

Most helpful comment

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

  • It is a duplicate of #2434
  • It works in test cases
  • It also fails using javac directly
  • The error message is totally misleading. An easy to fix lombok bug hides the original exception. The real stacktrace is:
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.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:147)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
        at org.gradle.internal.compiler.java.IncrementalCompileTask.call(IncrementalCompileTask.java:74)
  • Javac creates three arrays lvarOffset,lvarLength and lvarIndex and assumes that they always have the same length
  • At the same time it offers a method that only sets one of them and a method that always appends to all three (yay)
  • This commit might be relevant: https://github.com/openjdk/jdk/commit/229e0d16313b10932b9ce7506d84096696983699#diff-f3a303a12a61c99e953052638e511517
  • It seems to be related to source code positions
  • It seems to be fixed if we do not set positions for JCExpression but this might break some other things...

All 9 comments

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?

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

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

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! :)

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

  • It is a duplicate of #2434
  • It works in test cases
  • It also fails using javac directly
  • The error message is totally misleading. An easy to fix lombok bug hides the original exception. The real stacktrace is:
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.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:147)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
        at org.gradle.internal.compiler.java.IncrementalCompileTask.call(IncrementalCompileTask.java:74)
  • Javac creates three arrays lvarOffset,lvarLength and lvarIndex and assumes that they always have the same length
  • At the same time it offers a method that only sets one of them and a method that always appends to all three (yay)
  • This commit might be relevant: https://github.com/openjdk/jdk/commit/229e0d16313b10932b9ce7506d84096696983699#diff-f3a303a12a61c99e953052638e511517
  • It seems to be related to source code positions
  • It seems to be fixed if we do not set positions for JCExpression but this might break some other things...

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.

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

@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.

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
Was this page helpful?
0 / 5 - 0 ratings