Skip to content

Commit

Permalink
Merge pull request #21232 from mkouba/issue-21174
Browse files Browse the repository at this point in the history
ArC - fix regression with repeatable interceptor bindings
  • Loading branch information
mkouba authored Nov 8, 2021
2 parents 61a614e + 4c4fca6 commit f2cdc82
Show file tree
Hide file tree
Showing 17 changed files with 186 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ public void registerMethod(MethodInfo methodInfo) {
public void registerField(FieldInfo fieldInfo) {
reflectiveFields.produce(new ReflectiveFieldBuildItem(fieldInfo));
}

}, existingClasses.existingClasses, bytecodeTransformerConsumer,
config.shouldEnableBeanRemoval() && config.detectUnusedFalsePositives);
for (ResourceOutput.Resource resource : resources) {
Expand Down Expand Up @@ -497,6 +498,11 @@ public void registerField(FieldInfo fieldInfo) {
reflectiveClasses.produce(new ReflectiveClassBuildItem(true, false, qualifier.name().toString()));
}

// Register all interceptor bindings for reflection so that AnnotationLiteral.equals() works in a native image
for (ClassInfo binding : beanProcessor.getBeanDeployment().getInterceptorBindings()) {
reflectiveClasses.produce(new ReflectiveClassBuildItem(true, false, binding.name().toString()));
}

ArcContainer container = recorder.getContainer(shutdown);
BeanContainer beanContainer = recorder.initBeanContainer(container,
beanContainerListenerBuildItems.stream().map(BeanContainerListenerBuildItem::getBeanContainerListener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ abstract class AbstractGenerator {
static final String SYNTHETIC_SUFFIX = "Synthetic";

protected final boolean generateSources;
protected final ReflectionRegistration reflectionRegistration;

public AbstractGenerator(boolean generateSources) {
public AbstractGenerator(boolean generateSources, ReflectionRegistration reflectionRegistration) {
this.generateSources = generateSources;
this.reflectionRegistration = reflectionRegistration;
}

public AbstractGenerator(boolean generateSources) {
this(generateSources, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ public class AnnotationLiteralGenerator extends AbstractGenerator {

private static final Logger LOGGER = Logger.getLogger(AnnotationLiteralGenerator.class);

private final boolean generateSources;

AnnotationLiteralGenerator(boolean generateSources) {
super(generateSources);
this.generateSources = generateSources;
}

/**
Expand All @@ -72,7 +69,7 @@ Collection<Resource> generate(String name, BeanDeployment beanDeployment,
return resources;
}

static void createSharedAnnotationLiteral(ClassOutput classOutput, Key key, Literal literal, Set<String> existingClasses) {
void createSharedAnnotationLiteral(ClassOutput classOutput, Key key, Literal literal, Set<String> existingClasses) {
// Ljavax/enterprise/util/AnnotationLiteral<Lcom/foo/MyQualifier;>;Lcom/foo/MyQualifier;
String signature = String.format("Ljavax/enterprise/util/AnnotationLiteral<L%1$s;>;L%1$s;",
key.annotationName.toString().replace('.', '/'));
Expand Down Expand Up @@ -113,6 +110,7 @@ static void createSharedAnnotationLiteral(ClassOutput classOutput, Key key, Lite
generateStaticFieldsWithDefaultValues(annotationLiteral, defaultOfClassType);

annotationLiteral.close();

LOGGER.debugf("Shared annotation literal generated: %s", literal.className);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public class BeanGenerator extends AbstractGenerator {
protected final AnnotationLiteralProcessor annotationLiterals;
protected final Predicate<DotName> applicationClassPredicate;
protected final PrivateMembersCollector privateMembers;
protected final ReflectionRegistration reflectionRegistration;
protected final Set<String> existingClasses;
protected final Map<BeanInfo, String> beanToGeneratedName;
protected final Predicate<DotName> injectionPointAnnotationsPredicate;
Expand All @@ -97,11 +96,10 @@ public BeanGenerator(AnnotationLiteralProcessor annotationLiterals, Predicate<Do
Set<String> existingClasses, Map<BeanInfo, String> beanToGeneratedName,
Predicate<DotName> injectionPointAnnotationsPredicate,
List<Function<BeanInfo, Consumer<BytecodeCreator>>> suppressConditionGenerators) {
super(generateSources);
super(generateSources, reflectionRegistration);
this.annotationLiterals = annotationLiterals;
this.applicationClassPredicate = applicationClassPredicate;
this.privateMembers = privateMembers;
this.reflectionRegistration = reflectionRegistration;
this.existingClasses = existingClasses;
this.beanToGeneratedName = beanToGeneratedName;
this.injectionPointAnnotationsPredicate = injectionPointAnnotationsPredicate;
Expand Down Expand Up @@ -222,13 +220,11 @@ Collection<Resource> generateSyntheticBean(BeanInfo bean) {
implementGetIdentifier(bean, beanCreator);
implementSupplierGet(beanCreator);
if (!bean.hasDefaultDestroy()) {
implementDestroy(bean, beanCreator, providerType, Collections.emptyMap(), reflectionRegistration,
isApplicationClass, baseName);
implementDestroy(bean, beanCreator, providerType, Collections.emptyMap(), isApplicationClass, baseName);
}
implementCreate(classOutput, beanCreator, bean, providerType, baseName,
Collections.emptyMap(), Collections.emptyMap(),
Collections.emptyMap(), reflectionRegistration,
targetPackage, isApplicationClass);
Collections.emptyMap(), targetPackage, isApplicationClass);
implementGet(bean, beanCreator, providerType, baseName);

implementGetTypes(beanCreator, beanTypes.getFieldDescriptor());
Expand Down Expand Up @@ -312,15 +308,14 @@ Collection<Resource> generateClassBean(BeanInfo bean, ClassInfo beanClass) {
implementGetIdentifier(bean, beanCreator);
implementSupplierGet(beanCreator);
if (!bean.hasDefaultDestroy()) {
implementDestroy(bean, beanCreator, providerType, injectionPointToProviderSupplierField,
reflectionRegistration,
isApplicationClass, baseName);
implementDestroy(bean, beanCreator, providerType, injectionPointToProviderSupplierField, isApplicationClass,
baseName);
}
implementCreate(classOutput, beanCreator, bean, providerType, baseName,
injectionPointToProviderSupplierField,
interceptorToProviderSupplierField,
decoratorToProviderSupplierField,
reflectionRegistration, targetPackage, isApplicationClass);
targetPackage, isApplicationClass);
implementGet(bean, beanCreator, providerType, baseName);

implementGetTypes(beanCreator, beanTypes.getFieldDescriptor());
Expand Down Expand Up @@ -416,13 +411,12 @@ Collection<Resource> generateProducerMethodBean(BeanInfo bean, MethodInfo produc
implementGetIdentifier(bean, beanCreator);
implementSupplierGet(beanCreator);
if (!bean.hasDefaultDestroy()) {
implementDestroy(bean, beanCreator, providerType, injectionPointToProviderField, reflectionRegistration,
isApplicationClass, baseName);
implementDestroy(bean, beanCreator, providerType, injectionPointToProviderField, isApplicationClass, baseName);
}
implementCreate(classOutput, beanCreator, bean, providerType, baseName,
injectionPointToProviderField,
Collections.emptyMap(), Collections.emptyMap(),
reflectionRegistration, targetPackage, isApplicationClass);
targetPackage, isApplicationClass);
implementGet(bean, beanCreator, providerType, baseName);

implementGetTypes(beanCreator, beanTypes.getFieldDescriptor());
Expand Down Expand Up @@ -505,13 +499,11 @@ Collection<Resource> generateProducerFieldBean(BeanInfo bean, FieldInfo producer
implementGetIdentifier(bean, beanCreator);
implementSupplierGet(beanCreator);
if (!bean.hasDefaultDestroy()) {
implementDestroy(bean, beanCreator, providerType, null, reflectionRegistration, isApplicationClass,
baseName);
implementDestroy(bean, beanCreator, providerType, null, isApplicationClass, baseName);
}
implementCreate(classOutput, beanCreator, bean, providerType, baseName,
Collections.emptyMap(), Collections.emptyMap(),
Collections.emptyMap(), reflectionRegistration,
targetPackage, isApplicationClass);
Collections.emptyMap(), targetPackage, isApplicationClass);
implementGet(bean, beanCreator, providerType, baseName);

implementGetTypes(beanCreator, beanTypes.getFieldDescriptor());
Expand Down Expand Up @@ -727,7 +719,7 @@ protected MethodCreator initConstructor(ClassOutput classOutput, ClassCreator be
constructor.writeInstanceField(
FieldDescriptor.of(beanCreator.getClassName(), FIELD_NAME_BEAN_TYPES, Set.class.getName()),
constructor.getThis(),
constructor.invokeStaticInterfaceMethod(MethodDescriptors.SET_OF,
constructor.invokeStaticMethod(MethodDescriptors.SETS_OF,
typesArray));

// Qualifiers
Expand All @@ -750,7 +742,7 @@ protected MethodCreator initConstructor(ClassOutput classOutput, ClassCreator be
constructor.writeInstanceField(
FieldDescriptor.of(beanCreator.getClassName(), FIELD_NAME_QUALIFIERS, Set.class.getName()),
constructor.getThis(),
constructor.invokeStaticInterfaceMethod(MethodDescriptors.SET_OF,
constructor.invokeStaticMethod(MethodDescriptors.SETS_OF,
qualifiersArray));
}

Expand All @@ -765,15 +757,14 @@ protected MethodCreator initConstructor(ClassOutput classOutput, ClassCreator be
constructor.writeInstanceField(
FieldDescriptor.of(beanCreator.getClassName(), FIELD_NAME_STEREOTYPES, Set.class.getName()),
constructor.getThis(),
constructor.invokeStaticInterfaceMethod(MethodDescriptors.SET_OF,
constructor.invokeStaticMethod(MethodDescriptors.SETS_OF,
stereotypesArray));
}
return constructor;
}

protected void implementDestroy(BeanInfo bean, ClassCreator beanCreator, ProviderType providerType,
Map<InjectionPointInfo, String> injectionPointToProviderField, ReflectionRegistration reflectionRegistration,
boolean isApplicationClass, String baseName) {
Map<InjectionPointInfo, String> injectionPointToProviderField, boolean isApplicationClass, String baseName) {

MethodCreator destroy = beanCreator
.getMethodCreator("destroy", void.class, providerType.descriptorName(), CreationalContext.class)
Expand Down Expand Up @@ -908,7 +899,7 @@ protected void implementCreate(ClassOutput classOutput, ClassCreator beanCreator
Map<InjectionPointInfo, String> injectionPointToProviderSupplierField,
Map<InterceptorInfo, String> interceptorToProviderSupplierField,
Map<DecoratorInfo, String> decoratorToProviderSupplierField,
ReflectionRegistration reflectionRegistration, String targetPackage, boolean isApplicationClass) {
String targetPackage, boolean isApplicationClass) {

MethodCreator create = beanCreator.getMethodCreator("create", providerType.descriptorName(), CreationalContext.class)
.setModifiers(ACC_PUBLIC);
Expand Down Expand Up @@ -1410,7 +1401,7 @@ void implementCreateForClassBean(ClassOutput classOutput, ClassCreator beanCreat
ResultHandle invocationContextHandle = create.invokeStaticMethod(
MethodDescriptors.INVOCATION_CONTEXTS_AROUND_CONSTRUCT, constructorHandle,
aroundConstructsHandle, func.getInstance(),
create.invokeStaticInterfaceMethod(MethodDescriptors.SET_OF, bindingsArray));
create.invokeStaticMethod(MethodDescriptors.SETS_OF, bindingsArray));
TryBlock tryCatch = create.tryBlock();
CatchBlockCreator exceptionCatch = tryCatch.addCatch(Exception.class);
// throw new RuntimeException(e)
Expand Down Expand Up @@ -1542,7 +1533,7 @@ void implementCreateForClassBean(ClassOutput classOutput, ClassCreator beanCreat
// InvocationContextImpl.postConstruct(instance,postConstructs).proceed()
ResultHandle invocationContextHandle = create.invokeStaticMethod(
MethodDescriptors.INVOCATION_CONTEXTS_POST_CONSTRUCT, instanceHandle,
postConstructsHandle, create.invokeStaticInterfaceMethod(MethodDescriptors.SET_OF, bindingsArray));
postConstructsHandle, create.invokeStaticMethod(MethodDescriptors.SETS_OF, bindingsArray));

TryBlock tryCatch = create.tryBlock();
CatchBlockCreator exceptionCatch = tryCatch.addCatch(Exception.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ public class ClientProxyGenerator extends AbstractGenerator {

private final Predicate<DotName> applicationClassPredicate;
private final boolean mockable;
private final ReflectionRegistration reflectionRegistration;
private final Set<String> existingClasses;

public ClientProxyGenerator(Predicate<DotName> applicationClassPredicate, boolean generateSources, boolean mockable,
ReflectionRegistration reflectionRegistration, Set<String> existingClasses) {
super(generateSources);
super(generateSources, reflectionRegistration);
this.applicationClassPredicate = applicationClassPredicate;
this.mockable = mockable;
this.reflectionRegistration = reflectionRegistration;
this.existingClasses = existingClasses;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ Collection<Resource> generate(DecoratorInfo decorator) {
implementGetIdentifier(decorator, decoratorCreator);
implementSupplierGet(decoratorCreator);
implementCreate(classOutput, decoratorCreator, decorator, providerType, baseName,
injectionPointToProviderField,
Collections.emptyMap(), Collections.emptyMap(),
reflectionRegistration, targetPackage, isApplicationClass);
injectionPointToProviderField, Collections.emptyMap(), Collections.emptyMap(),
targetPackage, isApplicationClass);
implementGet(decorator, decoratorCreator, providerType, baseName);
implementGetTypes(decoratorCreator, beanTypes.getFieldDescriptor());
implementGetBeanClass(decorator, decoratorCreator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Collection<Resource> generate(InterceptorInfo interceptor) {
implementCreate(classOutput, interceptorCreator, interceptor, providerType, baseName,
injectionPointToProviderField,
Collections.emptyMap(), Collections.emptyMap(),
reflectionRegistration, targetPackage, isApplicationClass);
targetPackage, isApplicationClass);
implementGet(interceptor, interceptorCreator, providerType, baseName);
implementGetTypes(interceptorCreator, beanTypes.getFieldDescriptor());
implementGetBeanClass(interceptor, interceptorCreator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.quarkus.arc.impl.Objects;
import io.quarkus.arc.impl.Reflections;
import io.quarkus.arc.impl.RemovedBeanImpl;
import io.quarkus.arc.impl.Sets;
import io.quarkus.gizmo.MethodDescriptor;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -223,7 +224,7 @@ public final class MethodDescriptors {
public static final MethodDescriptor COLLECTIONS_EMPTY_MAP = MethodDescriptor.ofMethod(Collections.class, "emptyMap",
Map.class);

public static final MethodDescriptor SET_OF = MethodDescriptor.ofMethod(Set.class, "of", Set.class, Object[].class);
public static final MethodDescriptor SETS_OF = MethodDescriptor.ofMethod(Sets.class, "of", Set.class, Object[].class);

public static final MethodDescriptor ARC_CONTAINER = MethodDescriptor.ofMethod(Arc.class, "container", ArcContainer.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public class ObserverGenerator extends AbstractGenerator {
private final AnnotationLiteralProcessor annotationLiterals;
private final Predicate<DotName> applicationClassPredicate;
private final PrivateMembersCollector privateMembers;
private final ReflectionRegistration reflectionRegistration;
private final Set<String> existingClasses;
private final Map<ObserverInfo, String> observerToGeneratedName;
private final Predicate<DotName> injectionPointAnnotationsPredicate;
Expand All @@ -74,11 +73,10 @@ public ObserverGenerator(AnnotationLiteralProcessor annotationLiterals, Predicat
PrivateMembersCollector privateMembers, boolean generateSources, ReflectionRegistration reflectionRegistration,
Set<String> existingClasses, Map<ObserverInfo, String> observerToGeneratedName,
Predicate<DotName> injectionPointAnnotationsPredicate, boolean mockable) {
super(generateSources);
super(generateSources, reflectionRegistration);
this.annotationLiterals = annotationLiterals;
this.applicationClassPredicate = applicationClassPredicate;
this.privateMembers = privateMembers;
this.reflectionRegistration = reflectionRegistration;
this.existingClasses = existingClasses;
this.observerToGeneratedName = observerToGeneratedName;
this.injectionPointAnnotationsPredicate = injectionPointAnnotationsPredicate;
Expand Down Expand Up @@ -567,7 +565,7 @@ protected void createConstructor(ClassOutput classOutput, ClassCreator observerC
constructor.writeInstanceField(
FieldDescriptor.of(observerCreator.getClassName(), "qualifiers", Set.class.getName()),
constructor.getThis(),
constructor.invokeStaticInterfaceMethod(MethodDescriptors.SET_OF,
constructor.invokeStaticMethod(MethodDescriptors.SETS_OF,
qualifiersArray));
}

Expand Down
Loading

0 comments on commit f2cdc82

Please sign in to comment.