Skip to content

Commit

Permalink
Merge pull request quarkusio#41609 from geoand/default-method
Browse files Browse the repository at this point in the history
Fix bytecode recording issue when default method is used as a getter
  • Loading branch information
geoand authored Jul 3, 2024
2 parents f76e287 + bb0443b commit 1c3455a
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1235,9 +1235,16 @@ public void prepare(MethodContext context) {
public void handle(MethodContext context, MethodCreator method,
DeferredArrayStoreParameter out) {
//get the collection
ResultHandle prop = method.invokeVirtualMethod(
MethodDescriptor.ofMethod(i.getReadMethod()),
context.loadDeferred(out));
ResultHandle prop;
if (i.getReadMethod().isDefault()) {
prop = method.invokeInterfaceMethod(
MethodDescriptor.ofMethod(i.getReadMethod()),
context.loadDeferred(out));
} else {
prop = method.invokeVirtualMethod(
MethodDescriptor.ofMethod(i.getReadMethod()),
context.loadDeferred(out));
}
for (DeferredParameter i : params) {
//add the parameter
//TODO: this is not guarded against large collections, probably not an issue in practice
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.quarkus.extest.deployment;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.extest.runtime.def.ControllerConfigurationProducer;
import io.quarkus.extest.runtime.def.ControllerConfigurationRecorder;
import io.quarkus.extest.runtime.def.QuarkusControllerConfiguration;

public class ControllerConfigurationBuildStep {

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
public void record(ControllerConfigurationRecorder recorder, BuildProducer<AdditionalBeanBuildItem> producer) {
producer.produce(AdditionalBeanBuildItem.builder().addBeanClasses(ControllerConfigurationProducer.class).build());
recorder.setControllerConfiguration(new QuarkusControllerConfiguration("test1", "test2"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.quarkus.def;

import static org.assertj.core.api.Assertions.assertThat;

import jakarta.inject.Inject;

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

import io.quarkus.extest.runtime.def.ControllerConfiguration;
import io.quarkus.extest.runtime.def.QuarkusControllerConfiguration;
import io.quarkus.test.QuarkusUnitTest;

public class ControllerConfigurationTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withEmptyApplication();

@Inject
ControllerConfiguration controllerConfiguration;

@Test
public void test() {
assertThat(controllerConfiguration).isInstanceOfSatisfying(QuarkusControllerConfiguration.class,
quarkusControllerConfiguration -> {
assertThat(quarkusControllerConfiguration.getName()).isEqualTo("test1");
assertThat(quarkusControllerConfiguration.getResourceTypeName()).isEqualTo("test2");
assertThat(controllerConfiguration.getNamespaces()).containsOnly("foo", "bar");
assertThat(controllerConfiguration.getInformerListLimit()).isEmpty();
});

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.quarkus.extest.runtime.def;

public interface ControllerConfiguration extends ResourceConfiguration {

default String getName() {
return "name";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkus.extest.runtime.def;

import jakarta.inject.Singleton;

public class ControllerConfigurationProducer {

@Singleton
public ControllerConfiguration produce() {
return ControllerConfigurationRecorder.controllerConfiguration;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.quarkus.extest.runtime.def;

import io.quarkus.runtime.annotations.Recorder;

@Recorder
public class ControllerConfigurationRecorder {

public static volatile ControllerConfiguration controllerConfiguration;

public void setControllerConfiguration(QuarkusControllerConfiguration controllerConfiguration) {
ControllerConfigurationRecorder.controllerConfiguration = controllerConfiguration;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkus.extest.runtime.def;

import io.quarkus.runtime.annotations.RecordableConstructor;

public class QuarkusControllerConfiguration implements ControllerConfiguration {

private final String name;
private final String resourceTypeName;

@RecordableConstructor
public QuarkusControllerConfiguration(String name, String resourceTypeName) {
this.name = name;
this.resourceTypeName = resourceTypeName;
}

@Override
public String getName() {
return name;
}

public String getResourceTypeName() {
return resourceTypeName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.extest.runtime.def;

import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

public interface ResourceConfiguration {

default Set<String> getNamespaces() {
HashSet<String> set = new HashSet<>();
set.add("foo");
set.add("bar");
return set;
}

default Optional<Long> getInformerListLimit() {
return Optional.empty();
}
}

0 comments on commit 1c3455a

Please sign in to comment.