projectlombok / lombok

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

[BUG] `lombok.builder.className=Builder` breaks SuperBuilder #2647

Closed janinko closed 3 years ago

janinko commented 3 years ago

Describe the bug When building project with SuperBuilder classes and lombok.builder.className=Builder in config, I get compilation issues:

[ERROR] /home/jbrazdil/rht/pnc-api/src/main/java/org/jboss/pnc/api/deliverablesanalyzer/dto/MavenArtifact.java:[38,1] cannot find symbol
[ERROR]   symbol:   class ArtifactBuilder
[ERROR]   location: class org.jboss.pnc.api.deliverablesanalyzer.dto.Artifact

To Reproduce

@Data
@SuperBuilder
@Jacksonized
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonTypeInfo(
        use = JsonTypeInfo.Id.NAME,
        include = JsonTypeInfo.As.EXISTING_PROPERTY,
        property = "type",
        defaultImpl = Artifact.class)
@JsonSubTypes({ @JsonSubTypes.Type(value = MavenArtifact.class, name = "MAVEN") })
public class Artifact {

    @NotNull
    public final String artifactType;

    @NotBlank
    public final String filename;

    public final long size;

    @Pattern(regexp = "^[a-f0-9]{32}$")
    public final String md5;

    @Pattern(regexp = "^[a-f0-9]{40}$")
    public final String sha1;

    @Pattern(regexp = "^[a-f0-9]{64}$")
    public final String sha256;

}
@Data
@SuperBuilder
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Jacksonized
public class MavenArtifact extends Artifact {

    @NotBlank
    private final String groupId;

    @NotBlank
    private final String artifactId;

    @NotNull
    private final String type;

    @NotBlank
    private final String version;

    @NotEmpty
    private final String classifier;
}

Building these two files with lombok.builder.className=Builder fails, building them with lombok.builder.className=*Builder succeds.

Expected behavior SuperBuilder produces Artifact.Builder, Artifact.BuilderImpl, MavenArtifact.Builder and MavenArtifact.BuilderImpl classes.

Version info (please complete the following information):

janrieke commented 3 years ago

This one is strange. I can reproduce it in Eclipse, Maven, and delombok. However, everything works fine in a unit test.

The problem is that the extends clause of the MavenArtifact.Builder references Artifact.ArtifactBuilder<C, B> and not Artifact.Builder<C, B>.

Rawi01 commented 3 years ago

@janrieke I can reproduce it using this super simple unit test:

//CONF: lombok.builder.className = Builder

@lombok.experimental.SuperBuilder
class Parent {
    private final int parent;
}

@lombok.experimental.SuperBuilder
class Child extends Parent {
    private final int child;
}

The parent builder name seems to be hardcoded: https://github.com/rzwitserloot/lombok/blob/734b91ea97b825a8c323dabeba43ab45f5a54669/src/core/lombok/javac/handlers/HandleSuperBuilder.java#L258-L265