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

Also remove final from parent classes #23467

Merged
merged 1 commit into from
Feb 7, 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
@@ -0,0 +1,61 @@
package io.quarkus.arc.test.unproxyable;

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

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

public class FinalMethodRemoveFlagTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(FinalMethodRemoveFlagTest.class, MyBean.class, MyParent.class));

@Inject
MyBean bean;

@Test
public void testFinalFlagWasRemoved() {
assertEquals("ok", bean.ping());
assertEquals("parent", bean.parentPing());
}

// The final flag should normally result in deployment exception
@ApplicationScoped
public static class MyBean extends MyParent {

private String foo;

final String ping() {
return foo;
}

@PostConstruct
void init() {
foo = "ok";
}

}

public static class MyParent {

private String parent;

final String parentPing() {
return parent;
}

@PostConstruct
void parentInit() {
parent = "parent";
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -320,14 +319,16 @@ Collection<MethodInfo> getDelegatingMethods(BeanInfo bean, Consumer<BytecodeTran
IndexView index = bean.getDeployment().getBeanArchiveIndex();

if (bean.isClassBean()) {
Set<Methods.NameAndDescriptor> methodsFromWhichToRemoveFinal = new HashSet<>();
Map<String, Set<Methods.NameAndDescriptor>> methodsFromWhichToRemoveFinal = new HashMap<>();
ClassInfo classInfo = bean.getTarget().get().asClass();
Methods.addDelegatingMethods(index, classInfo,
methods, methodsFromWhichToRemoveFinal, transformUnproxyableClasses);
if (!methodsFromWhichToRemoveFinal.isEmpty()) {
String className = classInfo.name().toString();
bytecodeTransformerConsumer.accept(new BytecodeTransformer(className,
new Methods.RemoveFinalFromMethod(className, methodsFromWhichToRemoveFinal)));
for (Map.Entry<String, Set<Methods.NameAndDescriptor>> entry : methodsFromWhichToRemoveFinal.entrySet()) {
String className = entry.getKey();
bytecodeTransformerConsumer.accept(new BytecodeTransformer(className,
new Methods.RemoveFinalFromMethod(className, entry.getValue())));
}
}
} else if (bean.isProducerMethod()) {
MethodInfo producerMethod = bean.getTarget().get().asMethod();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static boolean isBridge(MethodInfo method) {
}

static void addDelegatingMethods(IndexView index, ClassInfo classInfo, Map<MethodKey, MethodInfo> methods,
Set<NameAndDescriptor> methodsFromWhichToRemoveFinal, boolean transformUnproxyableClasses) {
Map<String, Set<NameAndDescriptor>> methodsFromWhichToRemoveFinal, boolean transformUnproxyableClasses) {
if (classInfo != null) {
// First methods declared on the class
for (MethodInfo method : classInfo.methods()) {
Expand Down Expand Up @@ -110,7 +110,7 @@ static void addDelegatingMethods(IndexView index, ClassInfo classInfo, Map<Metho
}

private static boolean skipForClientProxy(MethodInfo method, boolean transformUnproxyableClasses,
Set<NameAndDescriptor> methodsFromWhichToRemoveFinal) {
Map<String, Set<NameAndDescriptor>> methodsFromWhichToRemoveFinal) {
if (Modifier.isStatic(method.flags()) || Modifier.isPrivate(method.flags())) {
return true;
}
Expand All @@ -125,7 +125,8 @@ private static boolean skipForClientProxy(MethodInfo method, boolean transformUn
String className = method.declaringClass().name().toString();
if (!className.startsWith("java.")) {
if (transformUnproxyableClasses && (methodsFromWhichToRemoveFinal != null)) {
methodsFromWhichToRemoveFinal.add(NameAndDescriptor.fromMethodInfo(method));
methodsFromWhichToRemoveFinal.computeIfAbsent(className, (k) -> new HashSet<>())
.add(NameAndDescriptor.fromMethodInfo(method));
return false;
}

Expand Down