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

ClassCastException on meta @Components with not Spring value [SPR-10580] #15209

Closed
spring-issuemaster opened this issue May 23, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented May 23, 2013

nebhale opened SPR-10580 and commented

New in 3.2.3.RELEASE there is a bug in how Spring determines bean names from annotations. The annotation that is causing the issue looks like:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Component
public @interface ConfigurationAnalyzer {

    ConfigurationType[] value();
}

Based on the stack trace generated by the bug, it's pretty straight forward where things are going wrong.

java.lang.ClassCastException: [L<REDACTED>.ConfigurationType; cannot be cast to java.lang.String
	at org.springframework.context.annotation.AnnotationBeanNameGenerator.determineBeanNameFromAnnotation(AnnotationBeanNameGenerator.java:91)
	at org.springframework.context.annotation.AnnotationBeanNameGenerator.generateBeanName(AnnotationBeanNameGenerator.java:69)
	at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:246)
	at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:123)
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:191)
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:165)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:140)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:282)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:223)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
<REDACTED>

Affects: 3.2.3

Reference URL: #289

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 3, 2013

Phil Webb commented

Hi Ben,

I am having a some difficulty tracking down what has caused thing to break with the latest release, did things work fine with 3.2.2? It looks like the specific line that throws the exception has not changed [1] so I suspect that this may be something to do with the AnnotationMetadata (or more specifically the type of AnnotationMetadata created by ConfigurationClassParser).

It appears that the AnnotationBeanNameGenerator is attempting to use the annotation value() when generating the name, so:

public @interface ConfigurationAnalyzer {
    String value();
}

Will would work, where as:

public @interface ConfigurationAnalyzer {
    ConfigurationType[] value();
}

Does not.

With the previous release did you have more than one ConfigurationAnalyzer annotated beans and did you ever refer to them by name?

[1] https://github.com/SpringSource/spring-framework/blob/v3.2.0.RELEASE/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java#L91

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 4, 2013

Phil Webb commented

The value of a meta-annotated @Component is now only considered if it is a String

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