Skip to content

Using @TargetType as a parameter for @Condition causes NPE during compiling. #2882

Description

@Zegveld

It is not that useful to use @TargetType with @Condition since the class that the @TargetType will return, is the same as the class of the conditional parameter.

found by @ivlcic while working on the TargetPropertyName annotation.

Reproduction:

import org.mapstruct.Condition;
import org.mapstruct.Mapper;
import org.mapstruct.TargetType;

@Mapper
public interface NPECheck {

    class Source {
        String val;

        public String getVal() {
            return val;
        }
    }

    class Target {
        String val;

        public void setVal(String val) {
            this.val = val;
        }
    }

    Target map(Source source);

    @Condition
    default boolean check(String val, @TargetType Class<?> type) {
        return true;
    }
}

log:

/home/helral/Documents/GitHub/Zegveld/mapstruct-bug/src/main/java/NPECheck.java:[6,8] 
Internal error in the mapping processor: java.lang.RuntimeException: 
org.mapstruct.ap.shaded.freemarker.core._TemplateModelException: 
Java method "org.mapstruct.ap.internal.model.MethodReference.inferTypeWhenEnum(org.mapstruct.ap.internal.model.common.Type)" threw an exception when invoked on org.mapstruct.ap.internal.model.MethodReference object "boolean #check()"; 
see cause exception in the Java stack trace.
    ----  FTL stack trace ("~" means nesting-related): 
- Failed at: @includeModel object=inferTypeWhenEnu...  [in template "org/mapstruct/ap/internal/model/MethodReference.ftl" in macro "arguments" at line 42, column 13]
- Reached through: #list parameterBindings as param  [in template "org/mapstruct/ap/internal/model/MethodReference.ftl" in macro "arguments" at line 39, column 5]
- Reached through: @arguments  [in template "org/mapstruct/ap/internal/model/MethodReference.ftl" in macro "methodCall" at line 32, column 53] 
- Reached through: @methodCall  [in template "org/mapstruct/ap/internal/model/MethodReference.ftl" at line 24, column 9]
  ----  	
at org.mapstruct.ap.internal.writer.ModelWriter.writeModel(ModelWriter.java:77)  	
at org.mapstruct.ap.internal.processor.MapperRenderingProcessor.createSourceFile(MapperRenderingProcessor.java:62)  	
at org.mapstruct.ap.internal.processor.MapperRenderingProcessor.writeToSourceFile(MapperRenderingProcessor.java:39)  	
at org.mapstruct.ap.internal.processor.MapperRenderingProcessor.process(MapperRenderingProcessor.java:29)  	
at org.mapstruct.ap.internal.processor.MapperRenderingProcessor.process(MapperRenderingProcessor.java:24)  	
at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:350)  	
at org.mapstruct.ap.MappingProcessor.processMapperTypeElement(MappingProcessor.java:330)  	
at org.mapstruct.ap.MappingProcessor.processMapperElements(MappingProcessor.java:279)  	
at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:174)  	
.... rest of stack trace omitted

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions