Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception thrown when mapping from nested Record field #3719

Closed
icod opened this issue Sep 17, 2024 · 2 comments
Closed

Exception thrown when mapping from nested Record field #3719

icod opened this issue Sep 17, 2024 · 2 comments

Comments

@icod
Copy link

icod commented Sep 17, 2024

Expected behavior

In MapStruct 1.6.0, it used to be possible to map from a nested Record, but this results in an exception in version 1.6.1.

Actual behavior

No code is generated by MapStruct; a ClassCastException is thrown:

Internal error in the mapping processor: java.lang.ClassCastException: class com.sun.tools.javac.code.Symbol$RecordComponent cannot be cast to class javax.lang.model.element.ExecutableElement (com.sun.tools.javac.code.Symbol$RecordComponent is in module jdk.compiler of loader 'app'; javax.lang.model.element.ExecutableElement is in module java.compiler of loader 'platform')
  	at org.mapstruct.ap.internal.model.common.TypeFactory.getThrownTypes(TypeFactory.java:494)
  	at org.mapstruct.ap.internal.model.NestedPropertyMappingMethod$Builder.build(NestedPropertyMappingMethod.java:75)
  	at org.mapstruct.ap.internal.model.PropertyMapping$PropertyMappingBuilder.getSourceRHS(PropertyMapping.java:641)
  	at org.mapstruct.ap.internal.model.PropertyMapping$PropertyMappingBuilder.build(PropertyMapping.java:232)
  	at org.mapstruct.ap.internal.model.BeanMappingMethod$Builder.handleDefinedMapping(BeanMappingMethod.java:1474)
  	at org.mapstruct.ap.internal.model.BeanMappingMethod$Builder.handleDefinedMappings(BeanMappingMethod.java:1165)
  	at org.mapstruct.ap.internal.model.BeanMappingMethod$Builder.build(BeanMappingMethod.java:292)
  	at org.mapstruct.ap.internal.processor.MapperCreationProcessor.getMappingMethods(MapperCreationProcessor.java:427)
  	at org.mapstruct.ap.internal.processor.MapperCreationProcessor.getMapper(MapperCreationProcessor.java:188)
  	at org.mapstruct.ap.internal.processor.MapperCreationProcessor.process(MapperCreationProcessor.java:142)
  	at org.mapstruct.ap.internal.processor.MapperCreationProcessor.process(MapperCreationProcessor.java:85)
  	at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:400)
  	at org.mapstruct.ap.MappingProcessor.processMapperTypeElement(MappingProcessor.java:380)
  	at org.mapstruct.ap.MappingProcessor.processMapperElements(MappingProcessor.java:329)
  	at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:213)
  	... 

Steps to reproduce the problem

I am using Temurin JDK 21.0.4.7-hotspot

public record MyRecord(String value) {}

public record Source(MyRecord myRecord) {}

public class Target {
    String targetValue;

    public Target(String targetValue) {
        this.targetValue = targetValue;
    }
}

Consider the following mapper:

@Mapper(componentModel = SPRING)
public interface MyNestedRecordMapper {

    @Mapping(source = "source.myRecord.value", target = "targetValue")
    Target mapToTarget(Source source);
}

Note that this is a mapper to illustrate the problem. In our project we use a mapper that take another input parameter (a String) and maps that directly onto the target object (POJO), so I hope that explains why I would define a seperate mapper for the nested record.

MapStruct Version

MapStruct 1.6.1

@icod icod added the bug label Sep 17, 2024
@filiphr
Copy link
Member

filiphr commented Sep 17, 2024

@icod this is already fixed with 1.6.2. See #3717. We had a regression, so we did a fix immediatelly after that.

@filiphr filiphr closed this as not planned Won't fix, can't repro, duplicate, stale Sep 17, 2024
@filiphr filiphr added duplicate and removed bug labels Sep 17, 2024
@icod
Copy link
Author

icod commented Sep 17, 2024

@filiphr Oh wow, that's fast!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants