java.lang.ClassCastException: [L<REDACTED>.ConfigurationType; cannot be cast to java.lang.String

Spring JIRA | nebhale | 4 years ago
  1. 0

    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: {code:java} @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @Component public @interface ConfigurationAnalyzer { ConfigurationType[] value(); } {code} Based on the stack trace generated by the bug, it's pretty straight forward where [things are going wrong|https://github.com/SpringSource/spring-framework/blob/v3.2.3.RELEASE/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java#L91]. {noformat} 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> {noformat}

    Spring JIRA | 4 years ago | nebhale
    java.lang.ClassCastException: [L<REDACTED>.ConfigurationType; cannot be cast to java.lang.String
  2. 0

    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: {code:java} @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @Component public @interface ConfigurationAnalyzer { ConfigurationType[] value(); } {code} Based on the stack trace generated by the bug, it's pretty straight forward where [things are going wrong|https://github.com/SpringSource/spring-framework/blob/v3.2.3.RELEASE/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java#L91]. {noformat} 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> {noformat}

    Spring JIRA | 4 years ago | nebhale
    java.lang.ClassCastException: [L<REDACTED>.ConfigurationType; cannot be cast to java.lang.String
  3. 0

    {code} java.lang.ClassCastException: org.springframework.data.mapping.context.MappingContextEvent cannot be cast to org.springframework.data.neo4j.event.AfterSaveEvent at com.xenoterracide.rpf.ui.Config$$Lambda$9/191715985.onApplicationEvent(Unknown Source) ~[na:na] at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:119) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.registerListeners(AbstractApplicationContext.java:809) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:764) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:357) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1124) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1113) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at com.xenoterracide.rpf.TestApplication.main(TestApplication.java:13) [test-classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45] at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45] {code} {code} @Bean public static ApplicationListener<AfterSaveEvent> characterSaveListener( final MBassador<CharacterEventMessage> bus ) { return event -> { Object entity = event.getEntity(); if ( entity instanceof Character ) { bus.post( CharacterEventMessage.saved( (Character) entity ) ); } }; } {code} happy to attempt to provide more info if necessary. It's possible this is just a documentation error.

    Spring JIRA | 10 months ago | Caleb Cushing
    java.lang.ClassCastException: org.springframework.data.mapping.context.MappingContextEvent cannot be cast to org.springframework.data.neo4j.event.AfterSaveEvent at com.xenoterracide.rpf.ui.Config$$Lambda$9/191715985.onApplicationEvent(Unknown Source) ~[na:na]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    {code} java.lang.ClassCastException: org.springframework.data.mapping.context.MappingContextEvent cannot be cast to org.springframework.data.neo4j.event.AfterSaveEvent at com.xenoterracide.rpf.ui.Config$$Lambda$9/191715985.onApplicationEvent(Unknown Source) ~[na:na] at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:119) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.registerListeners(AbstractApplicationContext.java:809) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:764) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:357) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1124) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1113) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE] at com.xenoterracide.rpf.TestApplication.main(TestApplication.java:13) [test-classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45] at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45] {code} {code} @Bean public static ApplicationListener<AfterSaveEvent> characterSaveListener( final MBassador<CharacterEventMessage> bus ) { return event -> { Object entity = event.getEntity(); if ( entity instanceof Character ) { bus.post( CharacterEventMessage.saved( (Character) entity ) ); } }; } {code} happy to attempt to provide more info if necessary. It's possible this is just a documentation error.

    Spring JIRA | 10 months ago | Caleb Cushing
    java.lang.ClassCastException: org.springframework.data.mapping.context.MappingContextEvent cannot be cast to org.springframework.data.neo4j.event.AfterSaveEvent at com.xenoterracide.rpf.ui.Config$$Lambda$9/191715985.onApplicationEvent(Unknown Source) ~[na:na]
  6. 0

    Bug ID: JDK-6499662 "java.lang.ClassCastException: cannot be cast to java.lang.String" happens from time to time

    sun.com | 4 months ago
    java.lang.ClassCastException: cannot be cast to java.lang.String

    1 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ClassCastException

      [L<REDACTED>.ConfigurationType; cannot be cast to java.lang.String

      at org.springframework.context.annotation.AnnotationBeanNameGenerator.determineBeanNameFromAnnotation()
    2. Spring Context
      AbstractApplicationContext.refresh
      1. org.springframework.context.annotation.AnnotationBeanNameGenerator.determineBeanNameFromAnnotation(AnnotationBeanNameGenerator.java:91)
      2. org.springframework.context.annotation.AnnotationBeanNameGenerator.generateBeanName(AnnotationBeanNameGenerator.java:69)
      3. org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:246)
      4. org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:123)
      5. org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:191)
      6. org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:165)
      7. org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:140)
      8. org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:282)
      9. org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:223)
      10. org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
      11. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
      11 frames