Skip to content

Commit

Permalink
ArC intercepted subclasses - skip private methods
Browse files Browse the repository at this point in the history
- that are not observers/producers
  • Loading branch information
mkouba committed Feb 3, 2023
1 parent 0f47d18 commit fc9c95a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,21 @@ Integer computeAlternativePriority(AnnotationTarget target, List<StereotypeInfo>
return alternativePriorities != null ? alternativePriorities.compute(target, stereotypes) : null;
}

Set<MethodInfo> getObserverAndProducerMethods() {
Set<MethodInfo> ret = new HashSet<>();
for (ObserverInfo observer : observers) {
if (!observer.isSynthetic()) {
ret.add(observer.getObserverMethod());
}
}
for (BeanInfo bean : beans) {
if (bean.isProducerMethod()) {
ret.add(bean.getTarget().get().asMethod());
}
}
return ret;
}

private void buildContextPut(String key, Object value) {
if (buildContext != null) {
buildContext.putInternal(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ private Map<MethodInfo, DecorationInfo> initDecoratedMethods() {
ClassInfo classInfo = target.get().asClass();
addDecoratedMethods(candidates, classInfo, classInfo, bound,
new SubclassSkipPredicate(beanDeployment.getAssignabilityCheck()::isAssignableFrom,
beanDeployment.getBeanArchiveIndex()));
beanDeployment.getBeanArchiveIndex(), beanDeployment.getObserverAndProducerMethods()));

Map<MethodInfo, DecorationInfo> decoratedMethods = new HashMap<>(candidates.size());
for (Entry<MethodKey, DecorationInfo> entry : candidates.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static Set<MethodInfo> addInterceptedMethodCandidates(BeanDeployment beanDeploym
return addInterceptedMethodCandidates(beanDeployment, classInfo, classInfo, candidates, Set.copyOf(classLevelBindings),
bytecodeTransformerConsumer, transformUnproxyableClasses,
new SubclassSkipPredicate(beanDeployment.getAssignabilityCheck()::isAssignableFrom,
beanDeployment.getBeanArchiveIndex()),
beanDeployment.getBeanArchiveIndex(), beanDeployment.getObserverAndProducerMethods()),
false, new HashSet<>());
}

Expand Down Expand Up @@ -518,14 +518,17 @@ static class SubclassSkipPredicate implements Predicate<MethodInfo> {

private final BiFunction<Type, Type, Boolean> assignableFromFun;
private final IndexView beanArchiveIndex;
private final Set<MethodInfo> producersAndObservers;
private ClassInfo clazz;
private ClassInfo originalClazz;
private List<MethodInfo> regularMethods;
private Set<MethodInfo> bridgeMethods = new HashSet<>();

public SubclassSkipPredicate(BiFunction<Type, Type, Boolean> assignableFromFun, IndexView beanArchiveIndex) {
public SubclassSkipPredicate(BiFunction<Type, Type, Boolean> assignableFromFun, IndexView beanArchiveIndex,
Set<MethodInfo> producersAndObservers) {
this.assignableFromFun = assignableFromFun;
this.beanArchiveIndex = beanArchiveIndex;
this.producersAndObservers = producersAndObservers;
}

void startProcessing(ClassInfo clazz, ClassInfo originalClazz) {
Expand Down Expand Up @@ -557,6 +560,10 @@ public boolean test(MethodInfo method) {
// Skip non-bridge synthetic methods
return true;
}
if (Modifier.isPrivate(method.flags()) && !producersAndObservers.contains(method)) {
// Skip a private method that is not and observer or producer
return true;
}
if (method.hasAnnotation(DotNames.POST_CONSTRUCT) || method.hasAnnotation(DotNames.PRE_DESTROY)) {
// @PreDestroy and @PostConstruct methods declared on the bean are NOT candidates for around invoke interception
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -24,7 +25,8 @@ public class SubclassSkipPredicateTest {
public void testPredicate() throws IOException {
IndexView index = Basics.index(Base.class, Submarine.class, Long.class, Number.class);
AssignabilityCheck assignabilityCheck = new AssignabilityCheck(index, null);
SubclassSkipPredicate predicate = new SubclassSkipPredicate(assignabilityCheck::isAssignableFrom, null);
SubclassSkipPredicate predicate = new SubclassSkipPredicate(assignabilityCheck::isAssignableFrom, null,
Collections.emptySet());

ClassInfo submarineClass = index.getClassByName(DotName.createSimple(Submarine.class.getName()));
predicate.startProcessing(submarineClass, submarineClass);
Expand Down

0 comments on commit fc9c95a

Please sign in to comment.