Skip to content

AnnotationReadingVisitorUtils.getMergedAnnotationAttributes() mutates the map argument [SPR-11710] #16332

Closed
@spring-projects-issues

Description

@spring-projects-issues

Gary Russell opened SPR-11710 and commented

Sam Brannen

List<AnnotationAttributes> attributesList = attributesMap.get(annotationType);
...
AnnotationAttributes results = attributesList.get(0);

...
    results.put(overridableAttributeName, value);

gets a hard reference to the map element and removes the value from that entry's list.

Consider:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@MessagingGateway(defaultRequestChannel = "gatewayChannel", defaultReplyChannel = "gatewayChannel",
		defaultHeaders = @GatewayHeader(name = "foo", value = "FOO"))
public static @interface TestMessagingGateway {

	String defaultRequestChannel() default "";

}

and

MultiValueMap<String, Object> metaAttributesMap = importingClassMetadata.getAllAnnotationAttributes(MessagingGateway.class.getName());
Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(MessagingGateway.class.getName());
metaAttributesMap = importingClassMetadata.getAllAnnotationAttributes(MessagingGateway.class.getName());

first call to getAllAnnotationAttributes():

{asyncExecutor=[], mapper=[], errorChannel=[], defaultRequestChannel=[gatewayChannel], ...

second call:

{name=[], asyncExecutor=[], mapper=[], errorChannel=[], defaultRequestChannel=[], ...

Affects: 4.0.3

Issue Links:

Referenced from: commits 82c32db, e1720d8

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions