[weld-dev] Class#getGenericInterfaces() on a CDI proxy

Marko Bekhta marko.prykladna at gmail.com
Tue Mar 13 09:38:12 EDT 2018


Hi all!

While working on an issue [1] in Hibernate Validator, We've stumbled on,
what
seems to be, a bug in Weld. We have a generic interface:

@ValidateOnExecution(type = { ExecutableType.NON_GETTER_METHODS,
ExecutableType.GETTER_METHODS })
public interface Repeater<T> {
String repeat(@NotNull String in);

@NotNull
T reverse(T in);

@NotNull
String getHelloWorld();
}

and then it's impl:

@ValidateOnExecution
public class DefaultRepeater implements Repeater<String> {

@Override
public String repeat(String in) {
return in;
}

@Override
public String reverse(String in) {
return null;
}

@Override
public String getHelloWorld() {
return null;
}
}

In the internals of HV we need to make a call to
`Class#getGenericInterfaces()`.
In case of calling it on `DefaultRepeater` class we will get something
similar
to:

result = {Type[1]@4948}
 0 = {ParameterizedTypeImpl at 4863} "org.hibernate.validator.test.
cdi.internal.methodvalidation.Repeater<java.lang.String>"

But in case when validation run in CDI context we receive a proxy instead
(something like org.hibernate.validator.test.cdi.internal.methodvalidation.
DefaultRepeater$Proxy$_$$_WeldSubclass).
And if we call `Class#getGenericInterfaces()` on such proxy we'd get next
results:

 result = {Class[6]@4880}
 0 = {Class at 3049} "interface org.hibernate.validator.test.
cdi.internal.methodvalidation.Repeater"
 1 = {Class at 327} "interface java.io.Serializable"
 2 = {Class at 4636} "interface org.jboss.weld.proxy.WeldConstruct"
 3 = {Class at 4638} "interface org.jboss.weld.interceptor.util.proxy.
TargetInstanceProxy"
 4 = {Class at 4637} "interface org.jboss.weld.interceptor.
proxy.LifecycleMixin"
 5 = {Class at 4639} "interface org.jboss.weld.bean.proxy.ProxyObject"

 The only line of interest here is 0. As you can see it gives a raw,
non-generic
 type, while `ParameterizedType` was expected (Repeater<java.lang.String>).

 Is that expected/intended behavior of `Class#getGenericInterfaces()`
 (returning raw types) for CDI proxies?

 Have a nice day,
 Marko

 [1] https://github.com/hibernate/hibernate-validator/pull/931#
issuecomment-372619324
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/weld-dev/attachments/20180313/c677c04a/attachment-0001.html 


More information about the weld-dev mailing list