org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is java.lang.ClassCastException: java.lang.Class cannot be cast to java.util.Map

Spring JIRA | Alexei Osipov | 3 years ago
  1. 0

    Referencing static field of class that extends Map in expression language causes class cast exception. Example: {code:java} public class A { public static final int X = 1; } public class B extends HashMap { public static final int X = 1; } {code} Expression {code}#{T(com.example.A).X}{code} resolves into value *1* (as expected). Expression {code}#{T(com.example.B).X}{code} throws class cast exception: {code}Caused by: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is java.lang.ClassCastException: java.lang.Class cannot be cast to java.util.Map at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:146) at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1364) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.evaluate(BeanDefinitionValueResolver.java:211) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:183) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:375) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:162) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ... 20 more Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.util.Map at org.springframework.context.expression.MapAccessor.canRead(MapAccessor.java:38) at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:198) at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85) at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:43) at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:346) at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:85) at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:102) at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:94) at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:143) ... 28 more {code}

    Spring JIRA | 3 years ago | Alexei Osipov
    org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is java.lang.ClassCastException: java.lang.Class cannot be cast to java.util.Map
  2. 0

    Referencing static field of class that extends Map in expression language causes class cast exception. Example: {code:java} public class A { public static final int X = 1; } public class B extends HashMap { public static final int X = 1; } {code} Expression {code}#{T(com.example.A).X}{code} resolves into value *1* (as expected). Expression {code}#{T(com.example.B).X}{code} throws class cast exception: {code}Caused by: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is java.lang.ClassCastException: java.lang.Class cannot be cast to java.util.Map at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:146) at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1364) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.evaluate(BeanDefinitionValueResolver.java:211) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:183) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:375) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:162) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ... 20 more Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.util.Map at org.springframework.context.expression.MapAccessor.canRead(MapAccessor.java:38) at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:198) at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85) at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:43) at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:346) at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:85) at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:102) at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:94) at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:143) ... 28 more {code}

    Spring JIRA | 3 years ago | Alexei Osipov
    org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is java.lang.ClassCastException: java.lang.Class cannot be cast to java.util.Map
  3. 0

    GenericMessage cannot be cast to java.util.Map - Spring Forum

    spring.io | 1 year ago
    org.springframework.amqp.rabbit.listener.ListenerExecutionFailedException: Listener threw exception
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    DataStax OpsCenter 4.0; running but can't run agents (can ssh to nodes from cmdline but OpsCenter can't

    Stack Overflow | 3 years ago | Brian Tarbox
    java.lang.ClassCastException: java.lang.Character cannot be cast to java.util.Map$Entry
  6. 0

    update DB function clojure

    Stack Overflow | 4 years ago | Gilad
    java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.util.Map$Entry

    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

      java.lang.Class cannot be cast to java.util.Map

      at org.springframework.context.expression.MapAccessor.canRead()
    2. Spring Context
      MapAccessor.canRead
      1. org.springframework.context.expression.MapAccessor.canRead(MapAccessor.java:38)
      1 frame
    3. Spring Expression Language (SpEL)
      SpelExpression.getValue
      1. org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:198)
      2. org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85)
      3. org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:43)
      4. org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:346)
      5. org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:85)
      6. org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:102)
      7. org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:94)
      7 frames
    4. Spring Context
      StandardBeanExpressionResolver.evaluate
      1. org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:143)
      2. org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:146)
      2 frames
    5. Spring Beans
      AbstractAutowireCapableBeanFactory.doCreateBean
      1. org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1364)
      2. org.springframework.beans.factory.support.BeanDefinitionValueResolver.evaluate(BeanDefinitionValueResolver.java:211)
      3. org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:183)
      4. org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:375)
      5. org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:162)
      6. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
      7. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
      8. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
      8 frames