Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-1102

Bean type Foo<B extends Bar> not assignable to required type Foo<Bar<Integer>>

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 1.1.7.Final
    • None
    • None
    • None

    Description

      There is a strange piece of code in org.jboss.weld.util.reflection.Reflections:

          public static boolean isAssignableFrom(Class<?> rawType1, Type[] actualTypeArguments1, Type type2) {
              ...
              } else if (type2 instanceof TypeVariable<?>) {
                  TypeVariable<?> typeVariable = (TypeVariable<?>) type2;
                  if (isTypeBounded(rawType1, actualTypeArguments1, typeVariable.getBounds())) {  <--- suspicious!
                      return true;
                  }
              }
              ...
          }
      
          public static boolean isTypeBounded(Type type, Type[] lowerBounds, Type[] upperBounds) {
              if (lowerBounds.length > 0) {
                  if (!isAssignableFrom(type, lowerBounds)) {
                      return false;
                  }
              }
              if (upperBounds.length > 0) {
                  if (!isAssignableFrom(upperBounds, type)) {
                      return false;
                  }
              }
              return true;
          }
      
      

      What's strange is that isTypeBounded() is called with actualTypeArguments1, which are actual type arguments of type1 (and not type2!).

      The result is that the bean type Foo<B extends Bar> is assignable to Foo<Bar<Baz>> (if Baz extends Bar), but it is NOT assignable to Foo<Bar<Integer>> just because Bar is not assignable from Integer.

      Attachments

        Activity

          People

            marko.luksa@gmail.com Marko Luksa (Inactive)
            marko.luksa@gmail.com Marko Luksa (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: