← 输入框|github.com|刷新
Skip to content

Unknown fields in @Ignored lead to an internal error #3902

Closed

Description

@thunderhook

Add an unknown field like "foo" to the ZooMapper which uses the new @Ignored annotation introduced with #3788, then this results in an error:

CompilationResultDescriptor [compilationResult=FAILED, diagnostics=[DiagnosticDescriptor: ERROR ZooMapper.java:13 Internal error in the mapping processor: java.lang.NullPointerException: Cannot invoke "javax.lang.model.element.Element.equals(Object)" because "e" is null
at org.mapstruct.ap.internal.processor.MapperAnnotatedFormattingMessenger.methodInMapperClass(MapperAnnotatedFormattingMessenger.java:140)
at org.mapstruct.ap.internal.processor.MapperAnnotatedFormattingMessenger.determineDelegationElement(MapperAnnotatedFormattingMessenger.java:136)
at org.mapstruct.ap.internal.processor.MapperAnnotatedFormattingMessenger.printMessage(MapperAnnotatedFormattingMessenger.java:69)
at org.mapstruct.ap.internal.model.BeanMappingMethod$Builder.handleDefinedMapping(BeanMappingMethod.java:1310)
at org.mapstruct.ap.internal.model.BeanMappingMethod$Builder.handleDefinedMappings(BeanMappingMethod.java:1175)
at org.mapstruct.ap.internal.model.BeanMappingMethod$Builder.build(BeanMappingMethod.java:296)
at org.mapstruct.ap.internal.model.AbstractBaseBuilder.lambda$createForgedAssignment$1(AbstractBaseBuilder.java:92)
at org.mapstruct.ap.internal.model.AbstractBaseBuilder.getOrCreateForgedAssignment(AbstractBaseBuilder.java:108)
at org.mapstruct.ap.internal.model.AbstractBaseBuilder.createForgedAssignment(AbstractBaseBuilder.java:95)
at org.mapstruct.ap.internal.model.PropertyMapping$PropertyMappingBuilder.forgeMapping(PropertyMapping.java:832)
at org.mapstruct.ap.internal.model.PropertyMapping$PropertyMappingBuilder.forgeMapping(PropertyMapping.java:796)
at org.mapstruct.ap.internal.model.PropertyMapping$PropertyMappingBuilder.forge(PropertyMapping.java:323)
at org.mapstruct.ap.internal.model.PropertyMapping$PropertyMappingBuilder.build(PropertyMapping.java:270)
at org.mapstruct.ap.internal.model.BeanMappingMethod$Builder.applyPropertyNameBasedMapping(BeanMappingMethod.java:1624)
at org.mapstruct.ap.internal.model.BeanMappingMethod$Builder.applyPropertyNameBasedMapping(BeanMappingMethod.java:1586)
at org.mapstruct.ap.internal.model.BeanMappingMethod$Builder.build(BeanMappingMethod.java:314)
at org.mapstruct.ap.internal.processor.MapperCreationProcessor.getMappingMethods(MapperCreationProcessor.java:432)
at org.mapstruct.ap.internal.processor.MapperCreationProcessor.getMapper(MapperCreationProcessor.java:189)
at org.mapstruct.ap.internal.processor.MapperCreationProcessor.process(MapperCreationProcessor.java:143)
at org.mapstruct.ap.internal.processor.MapperCreationProcessor.process(MapperCreationProcessor.java:86)
at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:373)

This should lead to a correct error instead of a stack trace.

Activity

  1. added this to the 1.7.0 milestone on Jul 20, 2025
  2. added theissue type on Jul 24, 2025
  3. znight1020 commented on Jul 29, 2025

    @znight1020
    Contributor

    Hi! I'd like to take on this issue.

    From what I understand, the problem is that if a non-existent field name is provided in the @Ignored annotation, the annotation processor throws an internal NullPointerException instead of a clear, user-friendly compile-time error.

    My proposed approach to fix this is as follows:

    1. First, I will write a new failing test case that reproduces the NullPointerException by using @Ignored with a property that doesn't exist in the source or target object.
    2. Based on the stack trace, I will locate the logic in BeanMappingMethod$Builder (or a related class) that resolves the properties listed in @Ignored.
    3. I will add a validation step to check if the property lookup was successful. If a property is not found (i.e., the result is null), I will use MapStruct's Messager utility to report a proper diagnostic error, such as "Unknown property 'foo' in @ignored."
    4. Finally, I'll ensure the new test passes with this change and that all existing tests are unaffected.

    As this would be my first contribution to MapStruct, I believe this is a great issue to get started with. Is anyone else currently working on this? If not, I would be happy to start working on a PR.

  4. added a commit that references this issue on Jul 29, 2025
  5. znight1020 commented on Jul 29, 2025

    @znight1020
    Contributor

    @thunderhook I've submitted a PR( #3908 ) that I believe resolves this issue. It includes a new test case and the corresponding fix.

    I'd appreciate it if you could take a look when you have a moment. Let me know if there are any other changes or tests required.
    Thank you!

  6. added a commit that references this issue on Jul 30, 2025
  7. thunderhook commented on Jul 30, 2025

    @thunderhook
    ContributorAuthor

    @znight1020 Thanks!

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

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions