Lombok: 1.16.22 constructor has private access

Created on 29 May 2018  Â·  5Comments  Â·  Source: projectlombok/lombok

I have two @Data beans in a parent/child relationship. The parent relies on @Data to generate the required constructor. The child declares its own constructor and calls super. When I compile, I get an error in the Child. Error:(6, 1) java: Base() has private access in com.example.Base

This is new in 1.16.22.

// Base.java
@Data
public class Base {
    private final String baseProperty;
}
// Child.java
@Data
@EqualsAndHashCode(callSuper = true)
public class Child extends Base {

    private final String childProperty;

    public Child(String baseProperty, String childProperty) {
        super(baseProperty);
        this.childProperty = childProperty;
    }
}



md5-7a90984c6a546043980eef31dccbdfc8



// build.gradle
plugins {
    id 'java'
}

sourceCompatibility = 10
targetCompatibility = 10

repositories {
    jcenter()
}

dependencies {
    annotationProcessor 'org.projectlombok:lombok:1.16.22'
    implementation 'org.projectlombok:lombok:1.16.22'
}

I can work around it if I declare a no-arg constructor in the base class manually and add @RequiredArgsConstructor, but this is ugly because I have to come up with defaults for the final fields.

Most helpful comment

If can also put a @NoArgsConstructor before the @Data like this:

@NoArgsConstructor
@Data
public class Foo {
}

All 5 comments

This could be related to the first feature in changelog: https://projectlombok.org/changelog

Related to Issue #1703

Adding lombok.noArgsConstructor.extraPrivate = false to lombok.config at the root of the project does avoid the issue. This seems like something that should be opt-in though and maybe needs some tuning for better decisions in an inheritance scenario. These classes are not serializable (though that may not matter for the frameworks this was introduced for).

If can also put a @NoArgsConstructor before the @Data like this:

@NoArgsConstructor
@Data
public class Foo {
}

If can also put a @NoArgsConstructor before the @Data like this:

@NoArgsConstructor
@Data
public class Foo {
}

holy。。。。

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arana198 picture arana198  Â·  53Comments

xiaolongzuo picture xiaolongzuo  Â·  32Comments

pbi-qfs picture pbi-qfs  Â·  37Comments

lombokissues picture lombokissues  Â·  61Comments

t-kuester picture t-kuester  Â·  31Comments