• Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Major Major
    • None
    • 2.1.0.Final
    • None
    • None

      Hey all,

      CDI proxies lose generic type information which screws up Resteasy:

      https://issues.jboss.org/browse/RESTEASY-985

      Basically, in the bug, an injected bean's method is losing parameter
      type information. Can you either:

      a) Fix weld proxies so that generic type information is not lost (in
      this case, it is method parameter type information). Preferred

      b) Have a supported way going forward to determine if the class is a CDI
      proxy. A marker interface or an annotation added to the proxy class
      would be best, then I wouldn't need to have a binary dependency on Weld
      and could do this via reflect calls.

            [WELD-1539] Proxy loses generic type information

            It seems that it's not technically possible to attach generic info 100% correctly and completely. Therefore, integrators are encouraged to detect client proxies and subclasses and work around the problem via reflection.

            Martin Kouba added a comment - It seems that it's not technically possible to attach generic info 100% correctly and completely. Therefore, integrators are encouraged to detect client proxies and subclasses and work around the problem via reflection.

            Also note that since 2.3.0.Beta1 and 3.0.0.Alpha11 classes generated by Weld are marked with the SYNTHETIC modifier.

            Martin Kouba added a comment - Also note that since 2.3.0.Beta1 and 3.0.0.Alpha11 classes generated by Weld are marked with the SYNTHETIC modifier.

            Actually, the referenced JDK bugs are not the only problems we've found. We're not able to attach the generic info properly if a method return type or parameters use a type variable declared deeper in the class hierarchy, e.g.:

            class Foo extends Bar<String> {
            }
            class Bar<T> {
              T get() {
              }
            }
            

            If a proxy class extends Foo, it also declares a method get() with signature TT;. However, T is not available in the scope of Foo (even if we add a class signature which would be something like LBar<Ljava/lang/String;>;) and the reflection API returns corrupted data. I'm not quite sure whether it should work or not. But this is how it's implemented in Oracle JDK 7 and 8.

            So we've decided to add a special marker interface into the Weld API to allow to detect a Weld proxy/subclass.

            Martin Kouba added a comment - Actually, the referenced JDK bugs are not the only problems we've found. We're not able to attach the generic info properly if a method return type or parameters use a type variable declared deeper in the class hierarchy, e.g.: class Foo extends Bar< String > { } class Bar<T> { T get() { } } If a proxy class extends Foo , it also declares a method get() with signature TT; . However, T is not available in the scope of Foo (even if we add a class signature which would be something like LBar<Ljava/lang/String;>; ) and the reflection API returns corrupted data . I'm not quite sure whether it should work or not. But this is how it's implemented in Oracle JDK 7 and 8. So we've decided to add a special marker interface into the Weld API to allow to detect a Weld proxy/subclass.

            Unfortunately, there are some JDK bugs which could block merging of pull/900.

            Martin Kouba added a comment - Unfortunately, there are some JDK bugs which could block merging of pull/900 .

            I have released classfilewriter 1.1.0.Final

            Stuart Douglas (Inactive) added a comment - I have released classfilewriter 1.1.0.Final

            We've added this functionality to jboss-classfilewriter: https://github.com/jbossas/jboss-classfilewriter/pull/4. Once 1.0.6.Final is released we're ready to add method signatures to proxy methods. We also consider making this configurable so that it's possible to disable this in some edge scenarios.

            Well, there is a marker interface already - org.jboss.weld.bean.proxy.ProxyObject. But it's not part of the Weld API and should not be used outside the weld codebase.

            Martin Kouba added a comment - We've added this functionality to jboss-classfilewriter: https://github.com/jbossas/jboss-classfilewriter/pull/4 . Once 1.0.6.Final is released we're ready to add method signatures to proxy methods. We also consider making this configurable so that it's possible to disable this in some edge scenarios. Well, there is a marker interface already - org.jboss.weld.bean.proxy.ProxyObject . But it's not part of the Weld API and should not be used outside the weld codebase.

              Unassigned Unassigned
              patriot1burke@gmail.com Bill Burke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: