0
votes

I am trying to add checker framework's Nullness checker to our project, however I am having problem with our MapStruct converters.

Converter example

Lets say I have a converter from User to UserDto like following:

@MapperConfig(componentModel = SPRING)
public interface UserToUserDtoConverter 
    extends org.springframework.core.convert.converter.Converter<User, UserDto> {
}

Which generates the following implementation:

@Override
public UserDto convert(User source) {
    if ( source == null ) {
        return null;
    }

    UserDtoBuilder<?, ?> userDto = UserDto.builder();
    userDto.id(source.getId());
    
    return userDto.build();
}

Problem

Now the problem is that Checker framework complains about the return null;, as the implementation does not have @Nullable above the convert method.

Another problem is when the converter uses other converters that are autowired here, which results in initialization.field.uninitialized error.

Things I have tried

Now I know that I could simply ignore converters completely with -AskipDefs, however I would still like it to let it check that there won't be a problem with assigning @Nullable value from User to @NonNull value in UserDto (and vice versa, which could leave a hole in the project).

Another solution that came to my mind was adding @SuppressWarning annotation for these error codes in the converter interface, however mapstruct is not capable of propagating any annotation to the implementation if I am not mistaken mapstruct-issues.

Stub files won't help here either.

Is here some kind of solution for handling the generated code?