java.lang.IllegalStateException: Could not obtain annotation attribute values

Spring JIRA | Keli Hlodversson | 3 years ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    If a member of a component candidate is annotated with an attribute, that again is annotated with a privately scoped meta-attribute containing values, the scanning will fail with an Illegal state exception caused by an IllegalAccessException caught in org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes. An example where this happens if one uses the rest.li framework in connection with spring: {code:title=RestMethod.java|borderStyle=solid} public class RestMethod { /** * This annotation defines mapping of RestMethod annotations to {@link com.linkedin.restli.common.ResourceMethod} */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.ANNOTATION_TYPE) private static @interface ToResourceMethod { ResourceMethod value(); } ... @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @ToResourceMethod(ResourceMethod.GET) public @interface Get { } ... } {code} {code:title=MyComponent.java|borderStyle=solid} @Component .... public class MyComponent extends SomeRestliBaseClass { @RestMethods.Get // Adding this attribute causes the stack trace below public ARecord get (String id) { .... } } {code} {noformat} org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file […]; nested exception is java.lang.IllegalStateException: Could not obtain annotation attribute values at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:290) at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242) at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84) at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73) at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438) at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) … Caused by: java.lang.IllegalStateException: Could not obtain annotation attribute values at org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes(AnnotationUtils.java:432) at org.springframework.core.type.classreading.AnnotationAttributesReadingVisitor.registerMetaAnnotations(AnnotationAttributesReadingVisitor.java:250) at org.springframework.core.type.classreading.AnnotationAttributesReadingVisitor.doVisitEnd(AnnotationAttributesReadingVisitor.java:241) at org.springframework.core.type.classreading.RecursiveAnnotationAttributesVisitor.visitEnd(AnnotationAttributesReadingVisitor.java:167) at org.springframework.asm.ClassReader.a(Unknown Source) at org.springframework.asm.ClassReader.accept(Unknown Source) at org.springframework.asm.ClassReader.accept(Unknown Source) at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:64) at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80) at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102) at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:266) at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242) at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84) … Caused by: java.lang.IllegalAccessException: Class org.springframework.core.annotation.AnnotationUtils can not access a member of class com.linkedin.restli.server.annotations.RestMethod$ToResourceMethod with modifiers "public abstract" at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:105) at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:261) at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:253) at java.lang.reflect.Method.invoke(Method.java:599) at org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes(AnnotationUtils.java:400) … {noformat}

    Spring JIRA | 3 years ago | Keli Hlodversson
    java.lang.IllegalStateException: Could not obtain annotation attribute values
  2. 0

    If a member of a component candidate is annotated with an attribute, that again is annotated with a privately scoped meta-attribute containing values, the scanning will fail with an Illegal state exception caused by an IllegalAccessException caught in org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes. An example where this happens if one uses the rest.li framework in connection with spring: {code:title=RestMethod.java|borderStyle=solid} public class RestMethod { /** * This annotation defines mapping of RestMethod annotations to {@link com.linkedin.restli.common.ResourceMethod} */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.ANNOTATION_TYPE) private static @interface ToResourceMethod { ResourceMethod value(); } ... @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @ToResourceMethod(ResourceMethod.GET) public @interface Get { } ... } {code} {code:title=MyComponent.java|borderStyle=solid} @Component .... public class MyComponent extends SomeRestliBaseClass { @RestMethods.Get // Adding this attribute causes the stack trace below public ARecord get (String id) { .... } } {code} {noformat} org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file […]; nested exception is java.lang.IllegalStateException: Could not obtain annotation attribute values at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:290) at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242) at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84) at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73) at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438) at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) … Caused by: java.lang.IllegalStateException: Could not obtain annotation attribute values at org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes(AnnotationUtils.java:432) at org.springframework.core.type.classreading.AnnotationAttributesReadingVisitor.registerMetaAnnotations(AnnotationAttributesReadingVisitor.java:250) at org.springframework.core.type.classreading.AnnotationAttributesReadingVisitor.doVisitEnd(AnnotationAttributesReadingVisitor.java:241) at org.springframework.core.type.classreading.RecursiveAnnotationAttributesVisitor.visitEnd(AnnotationAttributesReadingVisitor.java:167) at org.springframework.asm.ClassReader.a(Unknown Source) at org.springframework.asm.ClassReader.accept(Unknown Source) at org.springframework.asm.ClassReader.accept(Unknown Source) at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:64) at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80) at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102) at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:266) at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242) at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84) … Caused by: java.lang.IllegalAccessException: Class org.springframework.core.annotation.AnnotationUtils can not access a member of class com.linkedin.restli.server.annotations.RestMethod$ToResourceMethod with modifiers "public abstract" at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:105) at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:261) at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:253) at java.lang.reflect.Method.invoke(Method.java:599) at org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes(AnnotationUtils.java:400) … {noformat}

    Spring JIRA | 3 years ago | Keli Hlodversson
    java.lang.IllegalStateException: Could not obtain annotation attribute values

    Root Cause Analysis

    1. java.lang.IllegalStateException

      Could not obtain annotation attribute values

      at org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes()
    2. Spring Core
      CachingMetadataReaderFactory.getMetadataReader
      1. org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes(AnnotationUtils.java:432)
      2. org.springframework.core.type.classreading.AnnotationAttributesReadingVisitor.registerMetaAnnotations(AnnotationAttributesReadingVisitor.java:250)
      3. org.springframework.core.type.classreading.AnnotationAttributesReadingVisitor.doVisitEnd(AnnotationAttributesReadingVisitor.java:241)
      4. org.springframework.core.type.classreading.RecursiveAnnotationAttributesVisitor.visitEnd(AnnotationAttributesReadingVisitor.java:167)
      5. org.springframework.asm.ClassReader.a(Unknown Source)
      6. org.springframework.asm.ClassReader.accept(Unknown Source)
      7. org.springframework.asm.ClassReader.accept(Unknown Source)
      8. org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:64)
      9. org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
      10. org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
      10 frames
    3. Spring Context
      ComponentScanBeanDefinitionParser.parse
      1. org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:266)
      2. org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242)
      3. org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
      3 frames