mapstruct / mapstruct-idea

An IntelliJ IDEA plugin for working with MapStruct
Other
141 stars 38 forks source link

False positive missing mapping warning #192

Closed aleksvidak closed 6 months ago

aleksvidak commented 6 months ago

I have a property which is named settlementDate. It is present in both entity and dto and warning is not correct. Based on the warning message, maybe caused by name starting with 'set'.

Screenshot 2024-04-26 at 12 25 03
filiphr commented 6 months ago

@aleksvidak which version of the plugin are you using? Can you please share an example of how the setter looks like in the target class?

When I try it with something like

public class Target {

    public void setSettlementDate(String value) {
        //...
    }

}

then the set is not removed. It looks like:

image

thunderhook commented 6 months ago

@aleksvidak Is your target DTO a java record?

aleksvidak commented 6 months ago

@thunderhook yes, dto is a record.

filiphr commented 6 months ago

@thunderhook could you reproduce this with a record? I can't, it looks correct to me.

@aleksvidak which version of the plugin are you using?

thunderhook commented 6 months ago

@filiphr Yes I am seeing the same warning in this test class:

import org.mapstruct.Mapper;

@Mapper
interface Issue192Mapper {

    Target map(Source source);

}

class Source {
    String settlementDate;
}

record Target(String settlementDate) {}

However, I was not able to reproduce this in a unit test yet. Warning is also shown when using main with :runIde however, so this is not fixed yet.

filiphr commented 6 months ago

Which IntelliJ are you using locally>? Not the one with :runIde. I'm on 2024.1 and it is fine there. Might be a bug in IntelliJ

thunderhook commented 6 months ago

Used IntelliJ IDEA 2023.3.6 - Upgraded now to 2024.1 (Build #IU-241.14494.240) still there... 🤔

thunderhook commented 6 months ago

Okay, I'm slightly stupid. My example from above does indeed show the warning, since Source#settlementDate is not publicly accessible 🤦‍♂️ Changing it to public String settlementDate; removes the warning obviously.

@aleksvidak Could you please share your code? We're not able to reproduce this.

aleksvidak commented 6 months ago

My Intellij version is also 2024.1 (Build #IU-241.14494.240). Mapstruct version is 1.5.5.Final.

Seems like @SuperBuilder annotation is the issue.

@Mapper
interface TestMapper {

  Entity toEntity(Dto dto);
}

@SuperBuilder(toBuilder = true)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
class Entity {

  private LocalDate settlementDate;
}

record Dto(LocalDate settlementDate) {}
filiphr commented 6 months ago

@aleksvidak we had some issues with Lombok's @SuperBuilder (#159). Version 1.7.0 from the plugin has been released, can you please upgrade it and try it out? If it is still not working as expected will have another look at it.

aleksvidak commented 6 months ago

Seems like it works with 1.7.0, thank you for your help. 🙏🏻 I will close this one now.