Skip to content

Commit add7b26

Browse files
committed
Improved error message that might save an exhausted developer dealing with a monstrous constructor
1 parent f801726 commit add7b26

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/main/java/org/apache/ibatis/builder/ResultMappingConstructorResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private boolean verifyPropertyNaming(Set<String> constructorArgsByName) {
156156
// either specify all names and (optional random order), or type info.
157157
if (!allMappingsHavePropertyNames && !constructorArgsByName.isEmpty()) {
158158
throw new BuilderException("Error in result map '" + resultMapId
159-
+ "'. We do not support partially specifying a property name. Either specify all property names, or none.");
159+
+ "'. We do not support partially specifying a property name nor duplicates. Either specify all property names, or none.");
160160
}
161161

162162
return allMappingsHavePropertyNames;

src/test/java/org/apache/ibatis/builder/ResultMappingConstructorResolverTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,19 @@ void testThrowExceptionWithPartialPropertyNameSpecified() {
189189
.hasMessageContaining("Either specify all property names, or none.");
190190
}
191191

192+
@Test
193+
void testThrowExceptionWithDuplicatedPropertyNames() {
194+
ResultMapping mappingA = createConstructorMappingFor(Object.class, "a", "a");
195+
ResultMapping mappingB = createConstructorMappingFor(Object.class, "a", "b");
196+
ResultMapping mappingC = createConstructorMappingFor(LocalDate.class, "c", "c");
197+
198+
final ResultMappingConstructorResolver resolver = createResolverFor(ResultType1.class, TEST_ID, mappingA, mappingB,
199+
mappingC);
200+
201+
assertThatThrownBy(resolver::resolveWithConstructor).isInstanceOf(BuilderException.class)
202+
.hasMessageContaining("Either specify all property names, or none.");
203+
}
204+
192205
@Test
193206
void testCanResolveWithMissingPropertyNameAndAllTypeInfo() {
194207
ResultMapping mappingA = createConstructorMappingFor(long.class, null, "a");

0 commit comments

Comments
 (0)