Skip to content

Commit

Permalink
Fix ClientProxyGenerator
Browse files Browse the repository at this point in the history
- make sure that an interface method of an interface-based client proxy
is invoked upon the provider type and not the type that declares the
method
- fixes quarkusio#29593

(cherry picked from commit 4d51083)
  • Loading branch information
mkouba authored and gsmet committed Dec 6, 2022
1 parent bb7a01f commit 15c75c5
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ Collection<Resource> generate(BeanInfo bean, String beanClassName,
// Always use invokevirtual and the original descriptor for java.lang.Object#toString()
ret = forward.invokeVirtualMethod(originalMethodDescriptor, delegate, params);
} else if (isInterface) {
ret = forward.invokeInterfaceMethod(method, delegate, params);
// make sure we invoke the method upon the provider type, i.e. don't use the original method descriptor
MethodDescriptor virtualMethod = MethodDescriptor.ofMethod(providerType.className(),
originalMethodDescriptor.getName(),
originalMethodDescriptor.getReturnType(),
originalMethodDescriptor.getParameterTypes());
ret = forward.invokeInterfaceMethod(virtualMethod, delegate, params);
} else if (isReflectionFallbackNeeded(method, targetPackage)) {
// Reflection fallback
ResultHandle paramTypesArray = forward.newArray(Class.class, forward.load(method.parametersCount()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkus.arc.test.clientproxy.packageprivate;

// this interface is intentionally package-private
interface BaseInterface {

String ping();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.quarkus.arc.test.clientproxy.packageprivate;

public interface MyInterface extends BaseInterface {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkus.arc.test.clientproxy.packageprivate;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.arc.Arc;
import io.quarkus.arc.test.ArcTestContainer;
import io.quarkus.arc.test.clientproxy.packageprivate.foo.MyInterface2;
import io.quarkus.arc.test.clientproxy.packageprivate.foo.Producer;

public class PackagePrivateInterfaceInHierarchyTest {

@RegisterExtension
public ArcTestContainer container = new ArcTestContainer(BaseInterface.class, MyInterface.class, MyInterface2.class,
Producer.class);

@Test
public void testProducer() {
assertEquals("quarkus", Arc.container().instance(MyInterface2.class).get().ping());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkus.arc.test.clientproxy.packageprivate.foo;

import io.quarkus.arc.test.clientproxy.packageprivate.MyInterface;

public interface MyInterface2 extends MyInterface {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.quarkus.arc.test.clientproxy.packageprivate.foo;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;

@ApplicationScoped
public class Producer {

@Produces
@ApplicationScoped
public MyInterface2 myInterface2() {
return new MyInterface2() {
@Override
public String ping() {
return "quarkus";
}
};
}

}

0 comments on commit 15c75c5

Please sign in to comment.