Skip to content

Unused @AfterMapping does not trigger warning #3385

Description

@shoffmeister

Expected behavior

When a developer specifies @AfterMapping on a method (https://mapstruct.org/documentation/stable/reference/html/#customizing-mappings-with-before-and-after), and that method is not consumed by Mapstruct during code generation, then Mapstruct should emit a warning.

Rationale: The developer has declared an explicit intent that the method be used but may have made an implementation error. Not warning about this allows for subtle, hard-to-detect bugs (in particular if test coverage is not good).

Actual behavior

Mapstruct does not emit a warning that - in the reproducing case - "nowarning" is not consumed by Mapstruct.

Steps to reproduce the problem

import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;

@Mapper
public interface X {

    B map(A a);

    @AfterMapping
    default void good(A a) {
        //
    }

    @AfterMapping
    default void nowarning(String break_it, A a) {
        //
    }
}

MapStruct Version

1.5.5.Final

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions