Skip to content

JSpecify: broken code is generated #4088

Description

@chpasha

Expected behavior

Correct code is generated

Actual behavior

code that cannot be compiled is generated

Steps to reproduce the problem

I've created a repo to reproduce the problem https://github.com/chpasha/mapstruct_bug/tree/master/src/main/java/com/example/demo
for the update method of the mapper

public abstract class SwTerminMapper {
   @Mapping(target = "datum", source = "termin.termin")
    public abstract void updateFromRequest(UpdateSwTerminRequest request, @MappingTarget SwTermin termin);
    
}

following broken code is generated

@Override
    public void updateFromRequest(UpdateSwTerminRequest request, SwTermin termin) {

        if ( termin.getDatum() == null ) {
            termin.setDatum( new LocalDate() );
        }
        localDateTimeToLocalDate1( termin1, termin.getDatum() );
    }

here termin1 variable is undefined. if I remove jspecify (delete package-info.java)
correct code is generated like this

@Override
    public void updateFromRequest(UpdateSwTerminRequest request, SwTermin termin) {
        if ( request == null ) {
            return;
        }

        LocalDateTime termin1 = requestTerminTermin( request );
        if ( termin1 != null ) {
            if ( termin.getDatum() == null ) {
                termin.setDatum( new LocalDate() );
            }
            localDateTimeToLocalDate1( termin1, termin.getDatum() );
        }
        else {
            termin.setDatum( null );
        }
    }

It is important to notice, that LocalDate, LocalTime and LocalDateTime classes in my examples are custom, not from JDK (don't ask) - but they are crucial for replication of the bug, since they need conversion methods (which are correctly generated by mapstruct without intervention from my side)

MapStruct Version

MapStruct 1.7.0.Beta2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions