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

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

      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.

              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

                Created:
                Updated:
                Resolved: