Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure aroundInvoke interceptors get correct method parameters #29094

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1428,8 +1428,14 @@ void implementCreateForClassBean(ClassOutput classOutput, ClassCreator beanCreat
annotationLiterals.create(create, bindingClass, binding));
}

// ResultHandle of Object[] holding all constructor args
ResultHandle ctorArgsArray = create.newArray(Object.class, create.load(providerHandles.size()));
for (int i = 0; i < providerHandles.size(); i++) {
create.writeArrayValue(ctorArgsArray, i, providerHandles.get(i));
}
ResultHandle invocationContextHandle = create.invokeStaticMethod(
MethodDescriptors.INVOCATION_CONTEXTS_AROUND_CONSTRUCT, constructorHandle,
ctorArgsArray,
aroundConstructsHandle, func.getInstance(),
create.invokeStaticMethod(MethodDescriptors.SETS_OF, bindingsArray));
TryBlock tryCatch = create.tryBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public final class MethodDescriptors {
public static final MethodDescriptor INVOCATION_CONTEXTS_AROUND_CONSTRUCT = MethodDescriptor.ofMethod(
InvocationContexts.class,
"aroundConstruct",
InvocationContext.class, Constructor.class, List.class, Supplier.class, Set.class);
InvocationContext.class, Constructor.class, Object[].class, List.class, Supplier.class, Set.class);

public static final MethodDescriptor INVOCATION_CONTEXTS_POST_CONSTRUCT = MethodDescriptor.ofMethod(
InvocationContexts.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class AroundConstructInvocationContext extends LifecycleCallbackInvocationContex

private final Supplier<Object> aroundConstructForward;

AroundConstructInvocationContext(Constructor<?> constructor, Set<Annotation> interceptorBindings,
AroundConstructInvocationContext(Constructor<?> constructor, Object[] parameters, Set<Annotation> interceptorBindings,
List<InterceptorInvocation> chain, Supplier<Object> aroundConstructForward) {
super(null, constructor, interceptorBindings, chain);
super(null, constructor, parameters, interceptorBindings, chain);
this.aroundConstructForward = aroundConstructForward;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static Object performAroundInvoke(Object target, Method method,
*/
public static InvocationContext postConstruct(Object target, List<InterceptorInvocation> chain,
Set<Annotation> interceptorBindings) {
return new LifecycleCallbackInvocationContext(target, null, interceptorBindings, chain);
return new LifecycleCallbackInvocationContext(target, null, null, interceptorBindings, chain);
}

/**
Expand All @@ -54,7 +54,7 @@ public static InvocationContext postConstruct(Object target, List<InterceptorInv
*/
public static InvocationContext preDestroy(Object target, List<InterceptorInvocation> chain,
Set<Annotation> interceptorBindings) {
return new LifecycleCallbackInvocationContext(target, null, interceptorBindings, chain);
return new LifecycleCallbackInvocationContext(target, null, null, interceptorBindings, chain);
}

/**
Expand All @@ -65,10 +65,12 @@ public static InvocationContext preDestroy(Object target, List<InterceptorInvoca
* @return a new {@link javax.interceptor.AroundConstruct} invocation context
*/
public static InvocationContext aroundConstruct(Constructor<?> constructor,
Object[] parameters,
List<InterceptorInvocation> chain,
Supplier<Object> aroundConstructForward,
Set<Annotation> interceptorBindings) {
return new AroundConstructInvocationContext(constructor, interceptorBindings, chain, aroundConstructForward);
return new AroundConstructInvocationContext(constructor, parameters, interceptorBindings, chain,
aroundConstructForward);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class LifecycleCallbackInvocationContext extends AbstractInvocationContext {

private int position = 0;

LifecycleCallbackInvocationContext(Object target, Constructor<?> constructor, Set<Annotation> interceptorBindings,
List<InterceptorInvocation> chain) {
super(target, null, constructor, null, null, interceptorBindings, chain);
LifecycleCallbackInvocationContext(Object target, Constructor<?> constructor, Object[] parameters,
Set<Annotation> interceptorBindings, List<InterceptorInvocation> chain) {
super(target, null, constructor, parameters, null, interceptorBindings, chain);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.quarkus.arc.test.interceptors.aroundconstruct;

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

import java.util.concurrent.atomic.AtomicBoolean;

import javax.inject.Inject;
import javax.inject.Singleton;
import javax.interceptor.AroundConstruct;
import javax.interceptor.Interceptor;
Expand All @@ -20,7 +23,7 @@ public class AroundConstructTest {

@RegisterExtension
public ArcTestContainer container = new ArcTestContainer(MyTransactional.class, SimpleBean.class,
SimpleInterceptor.class);
SimpleInterceptor.class, MyDependency.class);

public static AtomicBoolean INTERCEPTOR_CALLED = new AtomicBoolean(false);

Expand All @@ -35,6 +38,25 @@ public void testInterception() {
@MyTransactional
static class SimpleBean {

@Inject
SimpleBean(MyDependency foo) {

}

}

@Singleton
static class MyDependency {

long created;

MyDependency() {
created = System.currentTimeMillis();
}

public long getCreated() {
return created;
}
}

@MyTransactional
Expand All @@ -44,6 +66,10 @@ public static class SimpleInterceptor {
@AroundConstruct
void mySuperCoolAroundConstruct(InvocationContext ctx) throws Exception {
INTERCEPTOR_CALLED.set(true);
assertTrue(ctx.getParameters().length == 1);
Object param = ctx.getParameters()[0];
assertTrue(param instanceof MyDependency);
assertEquals(Arc.container().instance(MyDependency.class).get().getCreated(), ((MyDependency) param).getCreated());
ctx.proceed();
}

Expand Down