Skip to content

Commit

Permalink
Also check descriptor when determining if final should be removed fro…
Browse files Browse the repository at this point in the history
…m bean
  • Loading branch information
geoand committed Nov 1, 2019
1 parent bba05f9 commit 28a35e4
Showing 1 changed file with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import static io.quarkus.arc.processor.IndexClassLookupUtils.getClassByName;

import io.quarkus.gizmo.DescriptorUtils;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Consumer;
Expand Down Expand Up @@ -122,7 +124,7 @@ static void addInterceptedMethodCandidates(BeanDeployment beanDeployment, ClassI
Map<MethodKey, Set<AnnotationInstance>> candidates,
List<AnnotationInstance> classLevelBindings, Consumer<BytecodeTransformer> bytecodeTransformerConsumer) {

Set<String> methodsFromWhichToRemoveFinal = new HashSet<>();
Set<NameAndDescriptor> methodsFromWhichToRemoveFinal = new HashSet<>();
for (MethodInfo method : classInfo.methods()) {
if (skipForSubclass(method)) {
continue;
Expand All @@ -143,7 +145,7 @@ static void addInterceptedMethodCandidates(BeanDeployment beanDeployment, ClassI
if (Modifier.isFinal(method.flags())) {
String className = method.declaringClass().name().toString();
if (!className.startsWith("java.")) {
methodsFromWhichToRemoveFinal.add(method.name());
methodsFromWhichToRemoveFinal.add(NameAndDescriptor.fromMethodInfo(method));
}
}
candidates.computeIfAbsent(new Methods.MethodKey(method), key -> merged);
Expand All @@ -158,7 +160,7 @@ public ClassVisitor apply(String s, ClassVisitor classVisitor) {
@Override
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature,
String[] exceptions) {
if (methodsFromWhichToRemoveFinal.contains(name)) {
if (methodsFromWhichToRemoveFinal.contains(new NameAndDescriptor(name, descriptor))) {
access = access & (~Opcodes.ACC_FINAL);
}
return super.visitMethod(access, name, descriptor, signature, exceptions);
Expand All @@ -176,6 +178,43 @@ public MethodVisitor visitMethod(int access, String name, String descriptor, Str
}
}

private static class NameAndDescriptor {
private final String name;
private final String descriptor;

public NameAndDescriptor(String name, String descriptor) {
this.name = name;
this.descriptor = descriptor;
}

public static NameAndDescriptor fromMethodInfo(MethodInfo method) {
String returnTypeDesc = DescriptorUtils.objectToDescriptor(method.returnType().name().toString());
String[] paramTypesDesc = new String[(method.parameters().size())];
for (int i = 0; i < method.parameters().size(); i++) {
paramTypesDesc[i] = DescriptorUtils.objectToDescriptor(method.parameters().get(i).name().toString());
}

return new NameAndDescriptor(method.name(),
DescriptorUtils.methodSignatureToDescriptor(returnTypeDesc, paramTypesDesc));
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
NameAndDescriptor that = (NameAndDescriptor) o;
return name.equals(that.name) &&
descriptor.equals(that.descriptor);
}

@Override
public int hashCode() {
return Objects.hash(name, descriptor);
}
}

private static boolean skipForSubclass(MethodInfo method) {
if (Modifier.isStatic(method.flags())) {
return true;
Expand Down

0 comments on commit 28a35e4

Please sign in to comment.