Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Redundant null check in generated code when adding parameters #3133

@mjiderhamn

Description

@mjiderhamn

Expected behavior

Given Foo1/Foo2 as simple beans

@Mapper
public interface FooMapper {
    void updateFoo(Foo1 input, @MappingTarget Foo2 toUpdate);
}

properly generates to

    @Override
    public void updateFoo(Foo1 input, Foo2 toUpdate) {
        if ( input == null ) {
            return;
        }

        toUpdate.setBar( input.getBar() );
    }

The expectation is to be able to add additional parameters (to be used in expressions) without SpotBugs/FindBugs reporting bugs in the generated code.

Actual behavior

@Mapper
public interface FooMapper {
    void updateFoo(Foo1 input, @MappingTarget Foo2 toUpdate, boolean baz);
}

generates

    @Override
    public void updateFoo(Foo1 input, Foo2 toUpdate, boolean baz) {
        if ( input == null ) {
            return;
        }

        if ( input != null ) {
            toUpdate.setBar( input.getBar() );
        }
    }

for which SpotBugs/FindBugs complains about Redundant null check RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE.

Steps to reproduce the problem

See above

MapStruct Version

1.5.3

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions