Uploaded image for project: 'Aries'
  1. Aries
  2. ARIES-1957

Using Generic types throws Unknown type exception

    XMLWordPrintableJSON

Details

    Description

      We are currently trying to migrate from Karaf 4.1.1 which uses Apache Aries Blueprint v1.8.0 to Karaf 4.2.6 which uses Aries Blueprint v1.10.2

      While we were able to handle beans with Generic constructors in the previous version, any usage of Generics now throws a RuntimeException saying the type is not known.
      With this definition in Blueprint :

      <bean id="sharedModel" class="javafx.beans.property.SimpleObjectProperty>
        <argument>
          <bean class="com.example.MySuperModel" />
        </argument>
      </bean>

      The definition of the javaFX class is like :

       

       

      public class SimpleObjectProperty<T> extends ObjectPropertyBase<T> {
        [...]
      
        public SimpleObjectProperty() {
          ...
        }
      
        public SimpleObjectProperty(T var) {
          ...
        }
      }

      The instanciation of this bean result in :

       

       

      2019-12-05T09:35:44,162 | ERROR | Blueprint Extender: 3 | org.apache.aries.blueprint.container.BlueprintContainerImpl | 102 - org.apache.aries.blueprint.core - 1.10.2 | Unable to start container for blueprint bundle com.test.hmi/1.4.0.SNAPSHOT
      org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to instantiate components
              at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:741) ~[102:org.apache.aries.blueprint.core:1.10.2]
              at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:433) [102:org.apache.aries.blueprint.core:1.10.2]
              at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:298) [102:org.apache.aries.blueprint.core:1.10.2]
              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
              at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
              at org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(ExecutorServiceWrapper.java:106) [102:org.apache.aries.blueprint.core:1.10.2]
              at org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:45) [102:org.apache.aries.blueprint.core:1.10.2]
              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
              at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
              at java.lang.Thread.run(Thread.java:834) [?:?]
      Caused by: java.lang.RuntimeException: Unknown type T
              at org.apache.aries.blueprint.utils.generics.TypeInference.getParameters(TypeInference.java:449) ~[?:?]
              at org.apache.aries.blueprint.utils.generics.TypeInference.match(TypeInference.java:262) ~[?:?]
              at org.apache.aries.blueprint.utils.generics.TypeInference.findMatching(TypeInference.java:231) ~[?:?]
              at org.apache.aries.blueprint.utils.generics.TypeInference.findMatchingConstructors(TypeInference.java:125) ~[?:?]
              at org.apache.aries.blueprint.container.BeanRecipe.findMatchingConstructors(BeanRecipe.java:373) ~[?:?]
              at org.apache.aries.blueprint.container.BeanRecipe.getInstanceFromType(BeanRecipe.java:346) ~[?:?]
              at org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:283) ~[?:?]
              at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:685) ~[?:?]
              at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:666) ~[?:?]
              at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:81) ~[?:?]
              at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
              at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:90) ~[?:?]
              at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:360) ~[?:?]
              at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:190) ~[?:?]
              at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:737) ~[?:?]
              ... 12 more
      
      

       

      We tried to investigate around this error trying to know if we made a mistake on our side.

      As far as we tested and tried to debug in the blueprint's classes, we found that when blueprint is matching constructors from what the class has and the parameters he received only Class and ParametrizedType are handled in TypeInference#getParameters(Type). But due to genericity, we arrived with a TypeVariable, which is of type T with Object as generic bound.
      So maybe this type can also be handled like other cases ?

      Attachments

        Issue Links

          Activity

            People

              jbonofre Jean-Baptiste Onofré
              Jerome M Jerome MICHEL
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: