Repository navigation
Description
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
znight1020 commentedon Jul 29, 2025
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
@Ignoredannotation, the annotation processor throws an internalNullPointerExceptioninstead of a clear, user-friendly compile-time error.My proposed approach to fix this is as follows:
NullPointerExceptionby using@Ignoredwith a property that doesn't exist in the source or target object.BeanMappingMethod$Builder(or a related class) that resolves the properties listed in@Ignored.null), I will use MapStruct'sMessagerutility to report a proper diagnostic error, such as "Unknown property 'foo' in @ignored."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.
build: exclude issue mapstruct#3902 from full feature test of integra…
znight1020 commentedon Jul 29, 2025
@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!
#3902: Validate unknown properties in @ignored
thunderhook commentedon Jul 30, 2025
@znight1020 Thanks!