GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Redundant if condition in Java record mapping with RETURN_DEFAULT strategy · Issue #3747 · mapstruct/mapstruct Closed DescriptionExpected behaviorThe generated code should avoid unnecessary empty @Override public ApiCategoryRecord mapRecord(Category category) { Long id = null; String title = null; if ( category != null ) { id = category.getId(); title = category.getTitle(); } ApiCategoryRecord apiCategoryRecord = new ApiCategoryRecord( id, title ); return apiCategoryRecord; } OR @Override public ApiCategoryRecord mapRecord(Category category) { if ( category != null ) { return new ApiCategoryRecord( category.getId(), category.getTitle() ); } else { return new ApiCategoryRecord( null, null ); } } Actual behaviorMapStruct generates an empty and unnecessary @Override public ApiCategoryRecord mapRecord(Category category) { Long id = null; String title = null; if ( category != null ) { id = category.getId(); title = category.getTitle(); } ApiCategoryRecord apiCategoryRecord = new ApiCategoryRecord( id, title ); if ( category != null ) { } return apiCategoryRecord; } Literally this is not a bug but a minor inefficiency in the generated code. Steps to reproduce the problemUse the following setup public class Category { private Long id; private String title; public Long getId() { return id; } public String getTitle() { return title; } } public record ApiCategoryRecord(Long id, String title) {} @Mapper(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) public interface ICategoryMapper { ApiCategoryRecord mapRecord(Category category); } MapStruct Version1.6.2 Activity
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |