Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-1974

BeanFactoryTypeConverter does not convert empty Collections even if the target requires a different type of Collection

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 2.0.4
    • Fix Version/s: 2.0.5
    • Component/s: Core
    • Labels:
      None

      Description

      If BeanFactoryTypeConverter is passed an empty collection, for example an empty ArrayList<String>, and is asked to convert it, for example into a Set<Integer>, it does not perform any conversion.

      In my particular scenario this is causing a SPEL expression to fail due to an argument type mismatch:

      Caused by: org.springframework.expression.AccessException: Problem invoking method: <omitted>
      	at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:73) ~[spring-expression-3.1.0.BUILD-20110713.075915-314.jar:3.1.0.CI-1143]
      	at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:109) ~[spring-expression-3.1.0.BUILD-20110713.075915-314.jar:3.1.0.CI-1143]
      	at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:57) ~[spring-expression-3.1.0.BUILD-20110713.075915-314.jar:3.1.0.CI-1143]
      	at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102) ~[spring-expression-3.1.0.BUILD-20110713.075915-314.jar:3.1.0.CI-1143]
      	at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:102) ~[spring-expression-3.1.0.BUILD-20110713.075915-314.jar:3.1.0.CI-1143]
      	at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:114) ~[spring-integration-core-2.0.4.RELEASE.jar:na]
      	at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:80) ~[spring-integration-core-2.0.4.RELEASE.jar:na]
      	... 80 common frames omitted
      Caused by: java.lang.IllegalArgumentException: argument type mismatch
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_15]
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_15]
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_15]
      	at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_15]
      	at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:69) ~[spring-expression-3.1.0.BUILD-20110713.075915-314.jar:3.1.0.CI-1143]
      	... 86 common frames omitted
      

      There used to be a similar problem with Spring's ConversionService, however this was recently fixed under SPR-7728. The code in BeanFactoryTypeConverter that's causing the problem is:

      if (value instanceof Collection<?> 
              && CollectionUtils.isEmpty((Collection<?>) value) 
              && Collection.class.isAssignableFrom(targetType.getObjectType())){
          return value;
      }
      

      I don't have much control over the value that's being passed into the SPEL expression as it's come from a JSON payload. I can workaround this by changing the method that's called by the SPEL expression to take a List, but I really need Set semantics.

      
      

        Attachments

          Activity

            People

            • Assignee:
              oleg.zhurakousky@springsource.com Oleg Zhurakousky
              Reporter:
              awilkinson Andy Wilkinson
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: