Uploaded image for project: 'Solder'
  1. Solder
  2. SOLDER-116

BeanBuilder create beans that don't support InjectionPoint injection

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Critical
    • Resolution: Out of Date
    • Affects Version/s: 3.0.0.Final
    • Fix Version/s: None
    • Component/s: Builders
    • Labels:
      None
    • Environment:
      MacOS X 10.7 (apple jdk 6) with Arquillian and weld-ee-embedded-1.1 container or JBoss AS 7

      Description

      I wrote a bean like this one :

      @MyQualifier
      public class MyBean {
       
          @Inject
          InjectionPoint ip;
       
          public String saySomething() {
              String value = "";
              if (ip != null)
                  value = ip.getAnnotated().getAnnotation(MyQualifier.class).value();
              return "Hello CDI World " + value;
          }
      }
      

      with MyQualifier being a simple qualifier with a non binding parameter value.
      And I wrote an extension which register another version of this bean without Qualifier

      public class MyExtension implements Extension {
       
          @SuppressWarnings({ "unchecked", "rawtypes" })
          public void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm) {
       
              AnnotatedTypeBuilder annoBuilder = new AnnotatedTypeBuilder().readFromType(MyBean.class).removeFromClass(
                      MyQualifier.class);
              AnnotatedType myAnnotatedType = annoBuilder.create();
       
              BeanBuilder beanBuilder = new BeanBuilder(bm).readFromType(myAnnotatedType);
              abd.addBean(beanBuilder.create());
          }
      }
      

      When bootstrapping Weld I have the following exception :

      org.jboss.weld.exceptions.DefinitionException: WELD-001405 Cannot inject [field] @Inject org.jboss.solderbug.MyBean.ip in a class which isnt a bean
      	at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:280)
      	at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:139)
      	at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:389)
      	at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:371)
      	at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:390)
      	at org.jboss.arquillian.container.weld.ee.embedded_1_1.mock.TestContainer.startContainer(TestContainer.java:257)
      	at org.jboss.arquillian.container.weld.ee.embedded_1_1.WeldEEMockContainer.deploy(WeldEEMockContainer.java:98)
      	...
      

      If I comment the @Inject line in the bean everything is fine and I can use both version of the bean (with or without qualifier)

        Gliffy Diagrams

          Activity

          Hide
          lightguard Jason Porter added a comment -

          I'm not sure if this has changed recently or not, but would you please try Beta4 and see if it's still a problem?

          Show
          lightguard Jason Porter added a comment - I'm not sure if this has changed recently or not, but would you please try Beta4 and see if it's still a problem?
          Hide
          antoinesabot-durand Antoine Sabot-Durand added a comment - - edited

          I updated my example application with last version of Solder(github project provided in step to reproduce section). The bug is still the same.
          In fact in a second thought I wonder if it's not a Weld bug since producing the code bellow (without Solder) produces the same bug :

              @SuppressWarnings({ "unchecked", "rawtypes" })
              public void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm) {
                  
                  // use this to read annotations of the class
                  AnnotatedType<MyBean> at = bm.createAnnotatedType(MyBean.class); // use this to instantiate the class and inject
                                                                                   // dependencies
                  final InjectionTarget<MyBean> it = bm.createInjectionTarget(at);
                  abd.addBean(new Bean<MyBean>() {
                      @Override
                      public Class<?> getBeanClass() {
                          return MyBean.class;
                      }
           
                      @Override
                      public Set<InjectionPoint> getInjectionPoints() {
                          return it.getInjectionPoints();
                      }
           
                      @Override
                      public String getName() {
                          return "myBean";
                      }
           
                      @Override
                      public Set<Annotation> getQualifiers() {
                          Set<Annotation> qualifiers = new HashSet<Annotation>();
                          qualifiers.add(new AnnotationLiteral<Default>() {
                          });
                          qualifiers.add(new AnnotationLiteral<Any>() {
                          });
                          return qualifiers;
                      }
           
                      @Override
                      public Class<? extends Annotation> getScope() {
                          return Dependent.class;
                      }
           
                      @Override
                      public Set<Class<? extends Annotation>> getStereotypes() {
                          return Collections.emptySet();
                      }
           
                      @Override
                      public Set<Type> getTypes() {
                          Set<Type> types = new HashSet<Type>();
                          types.add(MyBean.class);
                          types.add(Object.class);
                          return types;
                      }
           
                      @Override
                      public boolean isAlternative() {
                          return false;
                      }
           
                      @Override
                      public boolean isNullable() {
                          return false;
                      }
           
                      @Override
                      public MyBean create(CreationalContext<MyBean> ctx) {
                          MyBean instance = it.produce(ctx);
                          it.inject(instance, ctx);
                          it.postConstruct(instance);
                          return instance;
                      }
           
                      @Override
                      public void destroy(MyBean instance, CreationalContext<MyBean> ctx) {
                          it.preDestroy(instance);
                          it.dispose(instance);
                          ctx.release();
                      }
                  });
           
              }
          

          Can you take a few minutes to check if I'm doing something stupid in this code ? The goal is to have a bean registered twice, with and without the qualifier.

          thanks

          Show
          antoinesabot-durand Antoine Sabot-Durand added a comment - - edited I updated my example application with last version of Solder(github project provided in step to reproduce section). The bug is still the same. In fact in a second thought I wonder if it's not a Weld bug since producing the code bellow (without Solder) produces the same bug : @SuppressWarnings ({ "unchecked" , "rawtypes" }) public void afterBeanDiscovery( @Observes AfterBeanDiscovery abd, BeanManager bm) { // use this to read annotations of the class AnnotatedType<MyBean> at = bm.createAnnotatedType(MyBean. class ); // use this to instantiate the class and inject // dependencies final InjectionTarget<MyBean> it = bm.createInjectionTarget(at); abd.addBean( new Bean<MyBean>() { @Override public Class<?> getBeanClass() { return MyBean. class ; }   @Override public Set<InjectionPoint> getInjectionPoints() { return it.getInjectionPoints(); }   @Override public String getName() { return "myBean" ; }   @Override public Set<Annotation> getQualifiers() { Set<Annotation> qualifiers = new HashSet<Annotation>(); qualifiers.add( new AnnotationLiteral<Default>() { }); qualifiers.add( new AnnotationLiteral<Any>() { }); return qualifiers; }   @Override public Class<? extends Annotation> getScope() { return Dependent. class ; }   @Override public Set<Class<? extends Annotation>> getStereotypes() { return Collections.emptySet(); }   @Override public Set<Type> getTypes() { Set<Type> types = new HashSet<Type>(); types.add(MyBean. class ); types.add(Object. class ); return types; }   @Override public boolean isAlternative() { return false ; }   @Override public boolean isNullable() { return false ; }   @Override public MyBean create(CreationalContext<MyBean> ctx) { MyBean instance = it.produce(ctx); it.inject(instance, ctx); it.postConstruct(instance); return instance; }   @Override public void destroy(MyBean instance, CreationalContext<MyBean> ctx) { it.preDestroy(instance); it.dispose(instance); ctx.release(); } });   } Can you take a few minutes to check if I'm doing something stupid in this code ? The goal is to have a bean registered twice, with and without the qualifier. thanks
          Hide
          lightguard Jason Porter added a comment -

          Antoine, would you mind asking in #weld or #weld-dev, or ping Jozef?

          Show
          lightguard Jason Porter added a comment - Antoine, would you mind asking in #weld or #weld-dev, or ping Jozef?

            People

            • Assignee:
              jharting Jozef Hartinger
              Reporter:
              antoinesabot-durand Antoine Sabot-Durand
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development