org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 6): Method call: Method values() cannot be found on java.util.ArrayList type

Spring JIRA | Franck MARCHAND | 2 years ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    I think #this is not resolved correctly when it is used as an argument of a static method. If I try to execute this code : {code:title=TestExpr.java|borderStyle=solid} List<Map<String, Object>> myPayload = new ArrayList<Map<String, Object>>(); Map<String, Object> v1 = new HashMap<String, Object>(); Map<String, Object> v2 = new HashMap<String, Object>(); v1.put("test11", "test11"); v1.put("test12", "test12"); v2.put("test21", "test21"); v2.put("test22", "test22"); myPayload.add(v1); myPayload.add(v2); EvaluationContext context = new StandardEvaluationContext(myPayload); ExpressionParser parser=new SpelExpressionParser(); List res = parser.parseExpression("#root.![T(org.springframework.util.StringUtils).collectionToCommaDelimitedString(#this.values())]").getValue(context, List.class); {code} I get an exception : {code} org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 6): Method call: Method values() cannot be found on java.util.ArrayList type at org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:211) at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:125) at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:49) at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:342) at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88) at org.springframework.expression.spel.ast.MethodReference.getArguments(MethodReference.java:154) {code} In this case #this shouldn't be an ArrayList but a HashMap. If I don't use #this in the method collectionToCommaDelimitedString, but directly in the projection expression like this : {code} List res = parser.parseExpression("#root.![#this.values()]").getValue(context, List.class); {code} I don't have any exceptions and the result is the one I was expecting.

    Spring JIRA | 2 years ago | Franck MARCHAND
    org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 6): Method call: Method values() cannot be found on java.util.ArrayList type
  2. 0

    I think #this is not resolved correctly when it is used as an argument of a static method. If I try to execute this code : {code:title=TestExpr.java|borderStyle=solid} List<Map<String, Object>> myPayload = new ArrayList<Map<String, Object>>(); Map<String, Object> v1 = new HashMap<String, Object>(); Map<String, Object> v2 = new HashMap<String, Object>(); v1.put("test11", "test11"); v1.put("test12", "test12"); v2.put("test21", "test21"); v2.put("test22", "test22"); myPayload.add(v1); myPayload.add(v2); EvaluationContext context = new StandardEvaluationContext(myPayload); ExpressionParser parser=new SpelExpressionParser(); List res = parser.parseExpression("#root.![T(org.springframework.util.StringUtils).collectionToCommaDelimitedString(#this.values())]").getValue(context, List.class); {code} I get an exception : {code} org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 6): Method call: Method values() cannot be found on java.util.ArrayList type at org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:211) at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:125) at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:49) at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:342) at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88) at org.springframework.expression.spel.ast.MethodReference.getArguments(MethodReference.java:154) {code} In this case #this shouldn't be an ArrayList but a HashMap. If I don't use #this in the method collectionToCommaDelimitedString, but directly in the projection expression like this : {code} List res = parser.parseExpression("#root.![#this.values()]").getValue(context, List.class); {code} I don't have any exceptions and the result is the one I was expecting.

    Spring JIRA | 2 years ago | Franck MARCHAND
    org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 6): Method call: Method values() cannot be found on java.util.ArrayList type

    Root Cause Analysis

    1. org.springframework.expression.spel.SpelEvaluationException

      EL1004E:(pos 6): Method call: Method values() cannot be found on java.util.ArrayList type

      at org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod()
    2. Spring Expression Language (SpEL)
      MethodReference.getArguments
      1. org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:211)
      2. org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:125)
      3. org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:49)
      4. org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:342)
      5. org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88)
      6. org.springframework.expression.spel.ast.MethodReference.getArguments(MethodReference.java:154)
      6 frames