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

Support Class meta-annotation attributes with ASM-based annotation processing [SPR-11557] #16181

Closed
spring-projects-issues opened this issue Mar 14, 2014 · 13 comments
Assignees
Labels
in: core type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Mar 14, 2014

Sérgio Silva opened SPR-11557 and commented

I'm trying to create a composed annotation which uses @Configuration and @ComponentScan as meta-annotations.

@Configuration
@ComponentScan
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface BennuSpringModule {
    String[] basePackages() default {};

    String[] bundles() default {};
}

The problem appears in ConfigurationClassPostProcessor:

java.lang.IllegalArgumentException: Attribute 'nameGenerator' is of type [String], but [Class] was expected. Cause: 
	at org.springframework.core.annotation.AnnotationAttributes.doGet(AnnotationAttributes.java:117)
	at org.springframework.core.annotation.AnnotationAttributes.getClass(AnnotationAttributes.java:89)
	at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:82)
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:236)
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:205)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:173)
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:241)
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:205)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:182)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:152)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:299)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
	at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
	at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:530)
	at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
	at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
	at javax.servlet.GenericServlet.init(GenericServlet.java:160)
	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1091)
	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5317)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:744)

The meta-annotation is being processed with classValuesAsString set to true which breaks the look-up for Class Type. See AnnotationAttributesReadingVisitor for details.


Affects: 4.0.2

Issue Links:

  • #16198 Support meta-annotation attribute overrides in ASM-based annotation processing ("is depended on by")

Referenced from: commits 9ce0df8, e7b8a65, f1fbe85

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 14, 2014

Sam Brannen commented

Sérgio Silva, I attempted to reproduce the issue you describe; however, I was unsuccessful.

Please take a look at the unit and integration tests that I checked in with GitHub commit f1fbe85 and let me know if that adequately represents the configuration you are using.

If you are still experiencing the IllegalArgumentException, please provide us a project that reproduces the problem. Details on how to do that can be found in the README of the spring-framework-issues project on GitHub.

Can you also please confirm that you experience this issue against Spring Framework 4.0.2?

Thanks in advance for feedback!

Sam

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 14, 2014

Sérgio Silva commented

Updated stacktrace.

I can confirm it is 4.0.2. I will try to add an example test/project soon.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 16, 2014

Sam Brannen commented

Sérgio Silva, thanks for updating the stacktrace and confirming that this is against 4.0.2.

Based on your stacktrace, it is apparent that there is a problem; however, I have yet to come up with a test case that reproduces this. So, an example/test project would be very useful!

Please provide a test project or at least an example of the class hierarchy and exact annotations (including meta- and meta-meta-annotations) that you're using. The sooner you can do this, the better... since we plan to release Spring Framework 4.0.3 before the end of March.

We also need to know how you are bootstrapping the application context. It appears that you're experiencing the problem as the DispatcherServlet for your Spring MVC web application starts up, but knowing the details of your configuration might prove useful.

Thanks in advance!

Sam

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 16, 2014

Sérgio Silva commented

I tried to reproduce it based on your tests and also with the issues war-java project but unsuccessfully. I think this something specific with my setup since we have a multi-jar scenario, I will try to send you a setup where this is reproducible till midnight.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 16, 2014

Sam Brannen commented

I tried to reproduce it based on your tests and also with the issues war-java project but unsuccessfully. I think this something specific with my setup since we have a multi-jar scenario

I think it has something to do with how your application classes are loaded (e.g., a combination of JARs) and whether or not Spring has to use ASM or reflection to inspect the annotations on your classes. Thus your specific setup is likely required to reproduce this.

I will try to send you a setup where this is reproducible till midnight.

Thanks!

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 17, 2014

Sérgio Silva commented

Here it is, sorry for the delay :p

https://github.com/sergiofbsilva/spr11557/blob/master/README.md

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 18, 2014

Sam Brannen commented

Sérgio Silva, thanks for supplying us the example project!

That certainly helps. I am working on a solution and will keep you posted.

Regards,

Sam

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 18, 2014

Sam Brannen commented

Fixed as described in the comments for GitHub commit 9ce0df8:

Support Class meta-annotation attributes with ASM

Prior to this commit, AnnotationAttributesReadingVisitor treated Class
annotation attributes as Strings instead of Classes. As a result,
look-ups for Class attributes in meta-annotations failed with an
IllegalArgumentException.

This commit fixes this issue by consistently treating Class attributes
as Classes in AnnotationAttributesReadingVisitor.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 18, 2014

Sam Brannen commented

Sérgio Silva,

I have some good news and some bad news for you.

As you can see above, I have resolved this issue as Fixed. However, the scope is limited.

With the fix in place (available in the next snapshot build for Spring Framework 4.0.3), you should now be able to use @ComponentScan as a meta-annotation in your web application. However, analysis of your example application has revealed a much larger issue. Namely, Spring simply does not currently support meta-annotation attribute overrides -- like the basePackages attribute in your example -- when annotation processing is performed using ASM instead of reflection.

Thus, you will likely want to add yourself as as watcher for #16198.

Regards,

Sam

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 19, 2014

Sérgio Silva commented

Thanks for the feedback. I will wait for the fix!

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 19, 2014

Sam Brannen commented

Sérgio Silva, I just deployed your example application to Tomcat 7 against a local 4.0.3 snapshot for Spring that contains the fix for this issue and #16198, and when I access http://localhost:8080/xpto/spaces, I now see the following in the browser:

Hello World!This is my controller!

So it appears that your problem has been solved. Please test against the next 4.0.3.BUILD-SNAPSHOT build for Spring and let us know if everything looks good on your end.

Thanks,

Sam

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 31, 2014

Sérgio Silva commented

Working as expected with 4.0.3-RELEASE

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 2, 2014

Sam Brannen commented

Great!

Thanks for confirming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: bug
Projects
None yet
Development

No branches or pull requests

2 participants