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

Hierarchy injection is not working with external annotation type.

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 1.1.2.Final
    • 1.1.0.CR3
    • Weld SPI
    • None
    • Hide

      Create an extension wrapping an annotation type in class using injected fields (or methods) of its superclass.

      class Foo {
      @Inject BeanManager beanManager;
      }

      class Bar extends Foo {
      // beanManager will be null.
      }

      public <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat) {
      AnnotatedType<T> w = wrapAnnotatedType(pat.getAnnotatedType());
      pat.setAnnotatedType(w);
      }

      Show
      Create an extension wrapping an annotation type in class using injected fields (or methods) of its superclass. class Foo { @Inject BeanManager beanManager; } class Bar extends Foo { // beanManager will be null. } public <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat) { AnnotatedType<T> w = wrapAnnotatedType(pat.getAnnotatedType()); pat.setAnnotatedType(w); }

      In WeldClassImpl constructor, superclass is set as an Object.class when annotatedType is instanceof ExternalAnnotatedType (discovered flag). Why?
      This behavior causes a non injection of superclasses fields and methods. Is this correct ?

            [WELD-811] Hierarchy injection is not working with external annotation type.

            This issue is still present on 1.1.5.Final and 2.0.0.Alpha1

            For the simplest case:

            private <X> void processAnnotatedType(@Observes ProcessAnnotatedType<X> event) {
                final AnnotatedType<X> annotatedType = event.getAnnotatedType();
                event.setAnnotatedType(new AnnotatedType<X>() {
                    // delegate all methods to annotatedType
                });
            }
            

            This happens because BeanDeployer wraps modified annotated types with DiscoveredExternalAnnotatedType and WeldClassImpl sets superclass to Object (instead of the expected rawType.getSuperclass())

            Why?

            Gert Palok (Inactive) added a comment - This issue is still present on 1.1.5.Final and 2.0.0.Alpha1 For the simplest case: private <X> void processAnnotatedType(@Observes ProcessAnnotatedType<X> event) { final AnnotatedType<X> annotatedType = event.getAnnotatedType(); event.setAnnotatedType( new AnnotatedType<X>() { // delegate all methods to annotatedType }); } This happens because BeanDeployer wraps modified annotated types with DiscoveredExternalAnnotatedType and WeldClassImpl sets superclass to Object (instead of the expected rawType.getSuperclass()) Why?

            As I have not heard anything more on this I am going to assume that the 1.1.2 changes fixed the issue. If this is not the case then please file a new issue with a test case.

            Stuart Douglas (Inactive) added a comment - As I have not heard anything more on this I am going to assume that the 1.1.2 changes fixed the issue. If this is not the case then please file a new issue with a test case.

            I have made some changes in upstream that may have fixed this. If not, would you be able to post your complete wrapAnnotatedType method?

            Stuart Douglas (Inactive) added a comment - I have made some changes in upstream that may have fixed this. If not, would you be able to post your complete wrapAnnotatedType method?

            This method complements annotation of class, setting some default values.

            protected <X> AnnotatedType<X> wrapAnnotatedType(final AnnotatedType<X> at) {

            return new AnnotatedType<X>() {
            @Override
            public Set<Annotation> getAnnotations()

            { Set<Annotation> annotations = new HashSet<Annotation>(at.getAnnotations()); String defaultPathLiteral = at.getJavaClass()+"*"; annotations.add(new PlcUriPath(defaultPathLiteral)); return annotations; }

            ...
            }
            }

            Rogerio Baldini (Inactive) added a comment - This method complements annotation of class, setting some default values. protected <X> AnnotatedType<X> wrapAnnotatedType(final AnnotatedType<X> at) { return new AnnotatedType<X>() { @Override public Set<Annotation> getAnnotations() { Set<Annotation> annotations = new HashSet<Annotation>(at.getAnnotations()); String defaultPathLiteral = at.getJavaClass()+"*"; annotations.add(new PlcUriPath(defaultPathLiteral)); return annotations; } ... } }

            How does your wrapAnnotatedType method work?

            Pete Muir (Inactive) added a comment - How does your wrapAnnotatedType method work?

              sdouglas1@redhat.com Stuart Douglas (Inactive)
              rogerio.baldini_jira Rogerio Baldini (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: