Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1420

TypeUtils.isAssignable returns wrong result for GenericArrayType and ParameterizedType

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.7, 3.8
    • 3.12.0
    • lang.reflect.*
    • None

    Description

      TypeUtils.isAssignable returns a wrong result when checking whether a ParameterizedType is assignable to a GenericArrayType that has the same ParameterizedType as component type.

      For example:

      ParameterizedType componentType = TypeUtils.parameterize(java.lang.reflect.Constructor.class, java.awt.Insets.class);
      GenericArrayType arrayType = TypeUtils.genericArrayType(componentType);

      In this case,

      TypeUtils.isAssignable(arrayType, componentType) 

      returns true, but this should be false (the component type should not be assignable to the array type - the Java compiler complains about this).

       

      It seem that the problem is that the method:

      private static boolean isAssignable(final Type type, final ParameterizedType toParameterizedType, final Map<TypeVariable<?>, Type> typeVarAssigns)

      only compares the type parameters, since method getTypeArguments retrieves the component type using getGenericComponentType. There seems to be no check whether an array type is being assigned to a non-array in the first place.

      Attachments

        Activity

          People

            Unassigned Unassigned
            gofraser Gordon Fraser
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 50m
                50m