Skip to content

Commit 5d77255

Browse files
committed
report error in case of constructor-arg index ambiguity (SPR-6329)
1 parent d66fd98 commit 5d77255

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ private void addOrMergeIndexedArgumentValue(Integer key, ValueHolder newValue) {
131131
this.indexedArgumentValues.put(key, newValue);
132132
}
133133

134+
/**
135+
* Check whether an argument value has been registered for the given index.
136+
* @param index the index in the constructor argument list
137+
*/
138+
public boolean hasIndexedArgumentValue(int index) {
139+
return this.indexedArgumentValues.containsKey(index);
140+
}
141+
134142
/**
135143
* Get argument value for the given index in the constructor argument list.
136144
* @param index the index in the constructor argument list

org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,12 @@ public void parseConstructorArgElement(Element ele, BeanDefinition bd) {
778778
valueHolder.setName(nameAttr);
779779
}
780780
valueHolder.setSource(extractSource(ele));
781-
bd.getConstructorArgumentValues().addIndexedArgumentValue(index, valueHolder);
781+
if (bd.getConstructorArgumentValues().hasIndexedArgumentValue(index)) {
782+
error("Ambiguous constructor-arg entries for index " + index, ele);
783+
}
784+
else {
785+
bd.getConstructorArgumentValues().addIndexedArgumentValue(index, valueHolder);
786+
}
782787
}
783788
finally {
784789
this.parseState.pop();

0 commit comments

Comments
 (0)