Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-issuemaster opened this issue Sep 15, 2013 · 11 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Sep 15, 2013

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:

  • #15161 Filter source @Configuration with @ComponentScan
  • #16939 @Import in another annotation still results in double scan

0 votes, 5 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Sep 15, 2013

Oliver Drotbohm commented

This test case succeeds for me for both Spring 3.2.4 and current 4.0 snapshots: https://gist.github.com/olivergierke/6577399

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Sep 16, 2013

Clancy Kornie commented

Thanks for the fast response. I ran your test and it worked fine. However I wrote a new one which highlights the error. Try this instead:

@Test
public void invokesRegistrarOnlyOnce() {
    final AnnotationConfigApplicationContext myContext = new AnnotationConfigApplicationContext();
    myContext.scan(getClass().getPackage().getName());
    myContext.refresh();
    assertThat(TestImport.invocations, is(1));
}
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Sep 24, 2013

Phil Webb commented

I tried the updated test but it still succeeds for me. Could you you possible submit a pull request to https://github.com/SpringSource/spring-framework-issues with something that fails?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Sep 24, 2013

Clancy Kornie commented

Pull request sent.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Sep 24, 2013

Phil Webb commented

That was quick! Cheers.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Sep 24, 2013

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Sep 24, 2013

Phil Webb commented

Looks like this issue is only in 3.2.4. I think #15161 fixed in 4.0 but this has not been back-ported.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 10, 2013

Phil Webb commented

The 4.0 fix has now been back-ported to the 3.2.x branch.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 14, 2014

Alex Pogrebnyak commented

Still reproducible in 3.2.8.RELEASE version. Please reopen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 21, 2014

Phil Webb commented

Alex Pogrebnyak Ollie's gist (https://gist.github.com/olivergierke/6577399) passes for me with 3.2.8.RELEASE. Could you please open a new issue with the steps that you used to reproduce the problem?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 21, 2014

Juergen Hoeller commented

There's a new issue already: #16939. Let's continue the conversation there...

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.