Skip to content

Commit 3a60175

Browse files
committed
Fix @BeanParam handling during hot reload
Fixes: #45625
1 parent da144fe commit 3a60175

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.quarkus.resteasy.reactive.server.test.beanparam;
2+
3+
import static io.restassured.RestAssured.when;
4+
import static org.hamcrest.CoreMatchers.is;
5+
6+
import java.util.function.Supplier;
7+
8+
import org.jboss.shrinkwrap.api.ShrinkWrap;
9+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.extension.RegisterExtension;
12+
13+
import io.quarkus.test.QuarkusDevModeTest;
14+
15+
public class BeanParamRecordDevModeTest {
16+
17+
@RegisterExtension
18+
static QuarkusDevModeTest TEST = new QuarkusDevModeTest()
19+
.setArchiveProducer(new Supplier<>() {
20+
@Override
21+
public JavaArchive get() {
22+
return ShrinkWrap.create(JavaArchive.class).addClasses(FirstAndSecondResource.class,
23+
FirstAndSecondResource.Param.class);
24+
}
25+
});
26+
27+
@Test
28+
void test() {
29+
when().get("fs/foo/bar")
30+
.then()
31+
.statusCode(200)
32+
.body(is("foo-bar"));
33+
34+
TEST.modifySourceFile(FirstAndSecondResource.class, (orig) -> orig.replace("-", "#"));
35+
36+
when().get("fs/foo/bar")
37+
.then()
38+
.statusCode(200)
39+
.body(is("foo#bar"));
40+
}
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.quarkus.resteasy.reactive.server.test.beanparam;
2+
3+
import jakarta.ws.rs.GET;
4+
import jakarta.ws.rs.Path;
5+
6+
import org.jboss.resteasy.reactive.RestPath;
7+
8+
@Path("fs")
9+
public class FirstAndSecondResource {
10+
11+
@Path("{first}/{second}")
12+
@GET
13+
public String firstAndSecond(Param param) {
14+
return param.first() + "-" + param.second();
15+
}
16+
17+
public record Param(@RestPath String first, @RestPath String second) {
18+
19+
}
20+
}

independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/parameters/RecordBeanParamExtractor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.lang.invoke.MethodHandle;
44
import java.lang.invoke.MethodHandles;
5-
import java.lang.invoke.MethodType;
65

76
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;
87
import org.jboss.resteasy.reactive.server.injection.ResteasyReactiveInjectionContext;
@@ -13,8 +12,8 @@ public class RecordBeanParamExtractor implements ParameterExtractor {
1312

1413
public RecordBeanParamExtractor(Class<?> target) {
1514
try {
16-
factoryMethod = MethodHandles.lookup().findStatic(target, "__quarkus_rest_inject",
17-
MethodType.methodType(target, ResteasyReactiveInjectionContext.class));
15+
factoryMethod = MethodHandles.lookup()
16+
.unreflect(target.getMethod("__quarkus_rest_inject", ResteasyReactiveInjectionContext.class));
1817
} catch (NoSuchMethodException | IllegalAccessException e) {
1918
throw new RuntimeException("Failed to find target generated factory method on record @BeanParam type", e);
2019
}
@@ -27,7 +26,6 @@ public Object extractParameter(ResteasyReactiveRequestContext context) {
2726
} catch (RuntimeException e) {
2827
throw e;
2928
} catch (Throwable e) {
30-
e.printStackTrace();
3129
throw new RuntimeException("Failed to invoke generated factory method on record @BeanParam type", e);
3230
}
3331
}

0 commit comments

Comments
 (0)