From 25865b648841865d494fc10d17bd3870bd84b044 Mon Sep 17 00:00:00 2001 From: anenviousguest Date: Wed, 15 Oct 2025 13:34:19 +0200 Subject: [PATCH 1/7] #3943: Allow generation of methods with a sole argument of primitive type. --- .../processor/MethodRetrievalProcessor.java | 5 --- .../ap/test/bugs/_3943/Issue3943Mapper.java | 32 +++++++++++++++++++ .../ap/test/bugs/_3943/Issue3943Test.java | 24 ++++++++++++++ .../typemismatch/ErroneousMapper.java | 2 -- .../typemismatch/ErroneousMappingsTest.java | 4 --- 5 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 4bd2ed48a5..a9d2899a82 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -555,11 +555,6 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List clazz); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java index a045d16dfa..7a97548ca5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java @@ -44,10 +44,6 @@ public class ErroneousMappingsTest { @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 20, - message = "Can't generate mapping method with primitive parameter type."), - @Diagnostic(type = ErroneousMapper.class, - kind = Kind.ERROR, - line = 22, message = "Can't generate mapping method that has a parameter annotated with @TargetType.") } From 9238c8a2fe2982bfac94abd8999a537228ff2bec Mon Sep 17 00:00:00 2001 From: anenviousguest Date: Sat, 28 Feb 2026 22:59:31 +0100 Subject: [PATCH 2/7] #3943: Added test according to PR feedback. --- .../ap/test/bugs/_3943/Issue3943Mapper.java | 22 ++++++++++++++++--- .../ap/test/bugs/_3943/Issue3943Test.java | 11 ++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java index 94c2f156db..3847244f50 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java @@ -15,13 +15,16 @@ public interface Issue3943Mapper { Issue3943Mapper INSTANCE = Mappers.getMapper( Issue3943Mapper.class ); @Mapping(target = "value", source = "value") - Target map(int value); + TargetWithMatchingProperty mapWithMatchingProperty(int value); - class Target { + @Mapping(target = "nonMatchingProperty", source = "value") + TargetWithoutMatchingProperty mapWithoutMatchingProperty(int value); + + class TargetWithMatchingProperty { private final long value; - public Target(long value) { + public TargetWithMatchingProperty(long value) { this.value = value; } @@ -29,4 +32,17 @@ public long getValue() { return value; } } + + class TargetWithoutMatchingProperty { + + private final long nonMatchingProperty; + + public TargetWithoutMatchingProperty(long nonMatchingProperty) { + this.nonMatchingProperty = nonMatchingProperty; + } + + public long getNonMatchingProperty() { + return nonMatchingProperty; + } + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java index 0c20d597d3..0211edcf49 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java @@ -16,9 +16,16 @@ class Issue3943Test { @ProcessorTest - void shouldGenerateValidCode() { - Issue3943Mapper.Target target = Issue3943Mapper.INSTANCE.map( 42 ); + void shouldGenerateValidCodeForBeanWithMatchingProperty() { + Issue3943Mapper.TargetWithMatchingProperty target = Issue3943Mapper.INSTANCE.mapWithMatchingProperty( 42 ); assertThat( target ).isNotNull(); assertThat( target.getValue() ).isEqualTo( 42L ); } + + @ProcessorTest + void shouldGenerateValidCodeForBeanWithoutMatchingProperty() { + Issue3943Mapper.TargetWithoutMatchingProperty target = Issue3943Mapper.INSTANCE.mapWithoutMatchingProperty( 42 ); + assertThat( target ).isNotNull(); + assertThat( target.getNonMatchingProperty() ).isEqualTo( 42L ); + } } From 78bf465783dc2529ba21cb61ccd093c3531b4b32 Mon Sep 17 00:00:00 2001 From: anenviousguest Date: Sat, 28 Feb 2026 23:06:42 +0100 Subject: [PATCH 3/7] #3943: Added test according to PR feedback. --- .../org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java | 2 ++ .../org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java index 3847244f50..7cd171b1c8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java @@ -14,6 +14,8 @@ public interface Issue3943Mapper { Issue3943Mapper INSTANCE = Mappers.getMapper( Issue3943Mapper.class ); + TargetWithMatchingProperty mapImplicitly(int value); + @Mapping(target = "value", source = "value") TargetWithMatchingProperty mapWithMatchingProperty(int value); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java index 0211edcf49..750ca08fe9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java @@ -15,6 +15,13 @@ @WithClasses(Issue3943Mapper.class) class Issue3943Test { + @ProcessorTest + void shouldGenerateValidCodeForBeanWhenMappingImplicitly() { + Issue3943Mapper.TargetWithMatchingProperty target = Issue3943Mapper.INSTANCE.mapImplicitly( 42 ); + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( 42L ); + } + @ProcessorTest void shouldGenerateValidCodeForBeanWithMatchingProperty() { Issue3943Mapper.TargetWithMatchingProperty target = Issue3943Mapper.INSTANCE.mapWithMatchingProperty( 42 ); From daa1c2d1c38364abd7dc4e9258586d9817d0709e Mon Sep 17 00:00:00 2001 From: anenviousguest Date: Sat, 28 Feb 2026 23:23:05 +0100 Subject: [PATCH 4/7] #3943: Added negative test. --- .../bugs/_3943/Issue3943ErroneousMapper.java | 31 +++++++++++++++++++ .../ap/test/bugs/_3943/Issue3943Mapper.java | 14 +++++---- .../ap/test/bugs/_3943/Issue3943Test.java | 17 ++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943ErroneousMapper.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943ErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943ErroneousMapper.java new file mode 100644 index 0000000000..f74d1e84be --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943ErroneousMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3943; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) +public interface Issue3943ErroneousMapper { + + Issue3943ErroneousMapper INSTANCE = Mappers.getMapper( Issue3943ErroneousMapper.class ); + + Target map(int somethingElse); + + class Target { + + private final int value; + + public Target(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java index 7cd171b1c8..3a6c6a0047 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java @@ -16,6 +16,8 @@ public interface Issue3943Mapper { TargetWithMatchingProperty mapImplicitly(int value); +// TargetWithMatchingProperty mapImplicitlyWithoutMatchingProperty(int somethingElse); + @Mapping(target = "value", source = "value") TargetWithMatchingProperty mapWithMatchingProperty(int value); @@ -24,26 +26,26 @@ public interface Issue3943Mapper { class TargetWithMatchingProperty { - private final long value; + private final int value; - public TargetWithMatchingProperty(long value) { + public TargetWithMatchingProperty(int value) { this.value = value; } - public long getValue() { + public int getValue() { return value; } } class TargetWithoutMatchingProperty { - private final long nonMatchingProperty; + private final int nonMatchingProperty; - public TargetWithoutMatchingProperty(long nonMatchingProperty) { + public TargetWithoutMatchingProperty(int nonMatchingProperty) { this.nonMatchingProperty = nonMatchingProperty; } - public long getNonMatchingProperty() { + public int getNonMatchingProperty() { return nonMatchingProperty; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java index 750ca08fe9..af7cf325ef 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java @@ -5,9 +5,12 @@ */ package org.mapstruct.ap.test.bugs._3943; +import javax.tools.Diagnostic.Kind; + import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.*; import static org.assertj.core.api.Assertions.assertThat; @@ -35,4 +38,18 @@ void shouldGenerateValidCodeForBeanWithoutMatchingProperty() { assertThat( target ).isNotNull(); assertThat( target.getNonMatchingProperty() ).isEqualTo( 42L ); } + + @ProcessorTest + @WithClasses( { Issue3943ErroneousMapper.class } ) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = Issue3943ErroneousMapper.class, + kind = Kind.ERROR, + line = 16, + message = "Unmapped target property: \"value\"." ) + } + ) + void shouldFailToGenerateCodeIfPropertyNameDoesNotMatch() { + } } From a6544a877a4b4135aa6ea89819f24c9489715784 Mon Sep 17 00:00:00 2001 From: anenviousguest Date: Sat, 28 Feb 2026 23:26:11 +0100 Subject: [PATCH 5/7] #3943: Removed an unwanted comment. --- .../java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java index 3a6c6a0047..7dfac82cd5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Mapper.java @@ -16,8 +16,6 @@ public interface Issue3943Mapper { TargetWithMatchingProperty mapImplicitly(int value); -// TargetWithMatchingProperty mapImplicitlyWithoutMatchingProperty(int somethingElse); - @Mapping(target = "value", source = "value") TargetWithMatchingProperty mapWithMatchingProperty(int value); From ac66f90b5cb698b048453e14d09105c48bd1be80 Mon Sep 17 00:00:00 2001 From: anenviousguest Date: Sat, 28 Feb 2026 23:30:35 +0100 Subject: [PATCH 6/7] #3943: Fixed checkstyle issues. --- .../org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java index af7cf325ef..6e76837612 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java @@ -10,7 +10,9 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.compilation.annotation.*; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import static org.assertj.core.api.Assertions.assertThat; @@ -34,7 +36,8 @@ void shouldGenerateValidCodeForBeanWithMatchingProperty() { @ProcessorTest void shouldGenerateValidCodeForBeanWithoutMatchingProperty() { - Issue3943Mapper.TargetWithoutMatchingProperty target = Issue3943Mapper.INSTANCE.mapWithoutMatchingProperty( 42 ); + Issue3943Mapper.TargetWithoutMatchingProperty target = + Issue3943Mapper.INSTANCE.mapWithoutMatchingProperty( 42 ); assertThat( target ).isNotNull(); assertThat( target.getNonMatchingProperty() ).isEqualTo( 42L ); } From d815a77bfadc5c48b56d8b081525f73aa55db9d5 Mon Sep 17 00:00:00 2001 From: anenviousguest Date: Sat, 28 Feb 2026 23:45:15 +0100 Subject: [PATCH 7/7] #3943: Fixed alternative error line number. --- .../java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java | 1 + 1 file changed, 1 insertion(+) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java index 6e76837612..91693d33f1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3943/Issue3943Test.java @@ -50,6 +50,7 @@ void shouldGenerateValidCodeForBeanWithoutMatchingProperty() { @Diagnostic(type = Issue3943ErroneousMapper.class, kind = Kind.ERROR, line = 16, + alternativeLine = 17, message = "Unmapped target property: \"value\"." ) } )