Skip to content

Fix #4030 remove double getters in null checks#4064

Open
stefanos-kalantzis wants to merge 1 commit into
mapstruct:mainfrom
stefanos-kalantzis:fix-4030-remove-double-getters-in-null-checks
Open

Fix #4030 remove double getters in null checks#4064
stefanos-kalantzis wants to merge 1 commit into
mapstruct:mainfrom
stefanos-kalantzis:fix-4030-remove-double-getters-in-null-checks

Conversation

@stefanos-kalantzis

@stefanos-kalantzis stefanos-kalantzis commented Jun 5, 2026

Copy link
Copy Markdown

fixes #4030

Note: There is an edge-case considered out of scope for this PR, where source is used multiple times for different mappings. Then the generated code has multiple blocks with a different extracted variable, with incremental names. For example in DomainDtoWithNcvsAlwaysMapperImpl:

List<String> strings = source.getStrings();
if ( target.getStrings() != null ) {
    if ( source.hasStrings() ) {
        target.getStrings().clear();
        target.getStrings().addAll( strings );
    }
}
else {
    if ( source.hasStrings() ) {
        List<String> list = strings;
        target.setStrings( new LinkedHashSet<>( list ) );
    }
}
List<String> strings1 = source.getStrings();
if ( target.getLongs() != null ) {
    if ( source.hasStrings() ) {
        target.getLongs().clear();
        target.getLongs().addAll( stringListToLongSet( strings1 ) );
    }
}
else {
    if ( source.hasStrings() ) {
        target.setLongs( stringListToLongSet( strings1 ) );
    }
}

@stefanos-kalantzis stefanos-kalantzis force-pushed the fix-4030-remove-double-getters-in-null-checks branch from a50b711 to 3aa1ca6 Compare June 5, 2026 14:52
@stefanos-kalantzis stefanos-kalantzis force-pushed the fix-4030-remove-double-getters-in-null-checks branch from 3aa1ca6 to d727a50 Compare June 5, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Getters can be computed twice when nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS

1 participant