Skip to content

Stackoverflow with Immutables custom builder #3370

@creckord

Description

@creckord

Expected behavior

I have a value object making use of Immutables, which requires a customized builder class. It's defined like this:

@Value.Immutable
public abstract class ValueObject {
    public abstract String getFoo();
    public abstract Long getId();

    public static class Builder extends ImmutableValueObject.Builder {
       //some additional builder methods here
    }
}

And a POJO entity class like this:

public class ValueEntity {
    private String foo;
    protected Long id;

    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

    public String getFoo() { return foo; }
    public void setFoo(String foo) { this.foo = foo; }
}

And a simple Mapper definition that maps ValueEntity to ValueObject:

@Mapper
public abstract class Converter {
    public abstract ValueObject convert(ValueEntity valueEntity);
}

Expectation: The mapper implementation ConverterImpl is generated successfully and uses the builder generated by Immutables to create the ValueObject.

Actual behavior

Generating the mapper fails with a StackOverflowError in the annotation processor:

  	at org.mapstruct.ap.spi.ImmutablesBuilderProvider.findBuilderInfoForImmutables(ImmutablesBuilderProvider.java:58)
  	at org.mapstruct.ap.spi.ImmutablesBuilderProvider.findBuilderInfo(ImmutablesBuilderProvider.java:40)
  	at org.mapstruct.ap.spi.DefaultBuilderProvider.findBuilderInfo(DefaultBuilderProvider.java:96)
  	at org.mapstruct.ap.spi.DefaultBuilderProvider.findBuilderInfo(DefaultBuilderProvider.java:185)
  	at org.mapstruct.ap.spi.ImmutablesBuilderProvider.findBuilderInfoForImmutables(ImmutablesBuilderProvider.java:58)
  	at org.mapstruct.ap.spi.ImmutablesBuilderProvider.findBuilderInfo(ImmutablesBuilderProvider.java:40)
  	at org.mapstruct.ap.spi.DefaultBuilderProvider.findBuilderInfo(DefaultBuilderProvider.java:96)

Steps to reproduce the problem

Clone https://github.com/creckord/mapstruct-immutables-mcve and run ./gradlew clean classes

MapStruct Version

1.5.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugup-for-grabsIssues targeted for community contribution

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions