Skip to content

Commit 30d257b

Browse files
artembilangaryrussell
authored andcommitted
GH-1086: XML: Properly parse type attr
Fixes #1086 The `RabbitNamespaceUtils.parseContainer()` doesn't take into account that old schemas could be used for XML bean definitions, so, a new `type` can just not be defined in the target XSD at all leading to NPE during parsing phase * Wrap `type` attr population into the `if (containerEle.hasAttribute(TYPE)) {` **Cherry-pick to 2.1.x**
1 parent ccd177c commit 30d257b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/RabbitNamespaceUtils.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ private RabbitNamespaceUtils() {
119119
super();
120120
}
121121

122-
public static BeanDefinition parseContainer(Element containerEle, ParserContext parserContext) { // NOSONAR complexity
122+
public static BeanDefinition parseContainer(Element containerEle, ParserContext parserContext) { // NOSONAR
123+
// complexity
123124
RootBeanDefinition containerDef = new RootBeanDefinition(ListenerContainerFactoryBean.class);
124125
containerDef.setSource(parserContext.extractSource(containerEle));
125126

@@ -135,7 +136,13 @@ public static BeanDefinition parseContainer(Element containerEle, ParserContext
135136
containerDef.getPropertyValues().add("connectionFactory",
136137
new RuntimeBeanReference(connectionFactoryBeanName));
137138
}
138-
containerDef.getPropertyValues().add("type", new TypedStringValue(containerEle.getAttribute(TYPE)));
139+
140+
if (containerEle.hasAttribute(TYPE)) {
141+
String type = containerEle.getAttribute(TYPE);
142+
if (StringUtils.hasText(type)) {
143+
containerDef.getPropertyValues().add("type", new TypedStringValue(type));
144+
}
145+
}
139146

140147
String taskExecutorBeanName = containerEle.getAttribute(TASK_EXECUTOR_ATTRIBUTE);
141148
if (StringUtils.hasText(taskExecutorBeanName)) {
@@ -241,7 +248,7 @@ public static BeanDefinition parseContainer(Element containerEle, ParserContext
241248
if (StringUtils.hasText(recoveryBackOff)) {
242249
parserContext.getReaderContext()
243250
.error("'" + RECOVERY_INTERVAL + "' and '" + RECOVERY_BACK_OFF + "' are mutually exclusive",
244-
containerEle);
251+
containerEle);
245252
}
246253
containerDef.getPropertyValues().add("recoveryInterval", new TypedStringValue(recoveryInterval));
247254
}
@@ -284,7 +291,7 @@ public static BeanDefinition parseContainer(Element containerEle, ParserContext
284291
String retryDeclarationInterval = containerEle.getAttribute(MISSING_QUEUE_RETRY_INTERVAL);
285292
if (StringUtils.hasText(retryDeclarationInterval)) {
286293
containerDef.getPropertyValues().add("retryDeclarationInterval",
287-
new TypedStringValue(retryDeclarationInterval));
294+
new TypedStringValue(retryDeclarationInterval));
288295
}
289296

290297
String consumerTagStrategy = containerEle.getAttribute(CONSUMER_TAG_STRATEGY);

0 commit comments

Comments
 (0)