Skip to content

Duplicate scan of @Import annotations when inherited from another annotation [SPR-10918] #15546

@spring-projects-issues

Description

@spring-projects-issues

Clancy Kornie opened SPR-10918 and commented

I ran into a situation where classes can be scanned twice. It's quite easy to reproduce.

Given an annotation class:

@Import(TestImport.class)
public @interface AnotherImport {
}

And a configuration class which is annotated with the above:

@Configuration
@AnotherImport
public class TestConfiguration {
}

And the imported class:

public class TestImport implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(@NotNull AnnotationMetadata anImport, @NotNull BeanDefinitionRegistry aRegistry) {
        System.out.println("I am scanned twice!");
    }
}

You can see that the log message is printed twice. I don't believe this is correct behaviour. After debugging I believe the issue occurs in ConfigurationClassParser.collectImports where the annotation is resolved on AnotherImport as a class and on TestConfiguration as a string. Hence it is placed into the imports HashSet twice. Perhaps we could do the conversion from a String to a class at this stage?


Affects: 3.2.4

Issue Links:

0 votes, 5 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions