Lombok causing "Actual and formal arguments lists differ in length error"
Asked Answered
A

3

59

I have the following class:

@Builder @NoArgsConstructor
public class ConsultationPointOfContact {
    private String fullName;
    private String phoneNumber;
    private String userLogin;   
}

When the @Builder annotation exists, it is causing problems with the @NoArgsConstructor.

I am getting the error:

Error:(11, 1) java: constructor ConsultationPointOfContact in class models.ConsultationPointOfContact cannot be applied to given types;
  required: no arguments
  found: java.lang.String,java.lang.String,java.lang.String
  reason: actual and formal argument lists differ in length
Amok answered 14/3, 2018 at 16:1 Comment(0)
B
127

Add @AllArgsConstructor as well and this should fix the issue

Billingsgate answered 14/3, 2018 at 16:12 Comment(1)
The rules of @Builder state that there must be a suitable constructor (one for all fields). Normally builder makes one for you, but it doesn't if you either have an explicit constructorDaune
K
13

Met the same issue with lombok and gradle. The same code works with maven, but throws error when using the gradle way.

So the issue turns out to be with lombok and gradle, so I searched the keywords lombok gradle, and find an article: https://projectlombok.org/setup/gradle.

By referencing the article's tip and added the following to build.gradle, then it works like a charm!

...
dependencies {
...
    compileOnly 'org.projectlombok:lombok:1.18.22'
    annotationProcessor 'org.projectlombok:lombok:1.18.22'
    testCompileOnly 'org.projectlombok:lombok:1.18.22'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
...
}
...
Katinakatine answered 26/11, 2021 at 7:6 Comment(0)
F
8

For me works this: - upgrade or install Lombok plugin on IntellIJ and enable annotation processing checkbox for your module

enter image description here

Fascinator answered 30/11, 2018 at 23:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.