Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Private collection field with getter gives incorrect compilation error #2952

Copy link
Copy link

Description

@andye2004
Issue body actions

Erroneous Unmapped target property compilation error when private collection field has a get method but no set method.

Versions: Java 11, Mapstruct 1.5.2-Final.

Given the following classes:

public class Source {
    private String sourceField;

    public Source() {
        // no-op
    }

    public String getSourceField() {
        return sourceField;
    }

    public void setSourceField(String sourceField) {
        this.sourceField = sourceField;
    }
}

public class Target {
    private final Map<String, String> attributes = new HashMap<>();
    private String targetField;

    public Target() {
        // no-op
    }

    public Map<String, String> getAttributes() {
        return attributes;
    }

    public String getTargetField() {
        return targetField;
    }

    public void setTargetField(String targetField) {
        this.targetField = targetField;
    }
}

@Mapper
public interface S2TMapper {
    @Mapping(target = "targetField", source = "sourceField")
    Target map(Source source);
}

When the compiler is run we get the following compilation error.

image

If the getAttributes method is ommitted, everything compiles fine, so it seems Mapstruct mistakenly believes the field should be writable on the basis that it has an accessor.

NOTE: I haven't tested this with other collection type classes.

Reporoducible project here

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.