From 4d51083875e174105e2a53139f240b22e62814c8 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Tue, 6 Dec 2022 14:41:59 +0100 Subject: [PATCH] Fix ClientProxyGenerator - 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 #29593 --- .../arc/processor/ClientProxyGenerator.java | 7 +++++- .../packageprivate/BaseInterface.java | 7 ++++++ .../packageprivate/MyInterface.java | 5 ++++ ...ackagePrivateInterfaceInHierarchyTest.java | 24 +++++++++++++++++++ .../packageprivate/foo/MyInterface2.java | 7 ++++++ .../packageprivate/foo/Producer.java | 20 ++++++++++++++++ 6 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/BaseInterface.java create mode 100644 independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/MyInterface.java create mode 100644 independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/PackagePrivateInterfaceInHierarchyTest.java create mode 100644 independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/foo/MyInterface2.java create mode 100644 independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/foo/Producer.java diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ClientProxyGenerator.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ClientProxyGenerator.java index a3c63d605ddf7..a0e5fa6f38592 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ClientProxyGenerator.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ClientProxyGenerator.java @@ -205,7 +205,12 @@ Collection 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())); diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/BaseInterface.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/BaseInterface.java new file mode 100644 index 0000000000000..c1ea1982b7adf --- /dev/null +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/BaseInterface.java @@ -0,0 +1,7 @@ +package io.quarkus.arc.test.clientproxy.packageprivate; + +// this interface is intentionally package-private +interface BaseInterface { + + String ping(); +} diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/MyInterface.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/MyInterface.java new file mode 100644 index 0000000000000..7d87e859a45cd --- /dev/null +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/MyInterface.java @@ -0,0 +1,5 @@ +package io.quarkus.arc.test.clientproxy.packageprivate; + +public interface MyInterface extends BaseInterface { + +} diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/PackagePrivateInterfaceInHierarchyTest.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/PackagePrivateInterfaceInHierarchyTest.java new file mode 100644 index 0000000000000..fd3ad09ca61df --- /dev/null +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/PackagePrivateInterfaceInHierarchyTest.java @@ -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()); + } + +} diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/foo/MyInterface2.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/foo/MyInterface2.java new file mode 100644 index 0000000000000..f5fa6bd00d3f4 --- /dev/null +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/foo/MyInterface2.java @@ -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 { + +} diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/foo/Producer.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/foo/Producer.java new file mode 100644 index 0000000000000..3301df337c4c8 --- /dev/null +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/clientproxy/packageprivate/foo/Producer.java @@ -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"; + } + }; + } + +}