Skip to content

Commit dfb0ac9

Browse files
FroMagegsmet
authored andcommitted
Make sure we don't accept unannotated parameters for records
This does not apply to implicit record bean params, because they are not treated as implicit bean params if they do not contain any annotated field. (cherry picked from commit 09b71f4)
1 parent b16dcf2 commit dfb0ac9

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package io.quarkus.resteasy.reactive.server.test.beanparam;
2+
3+
import jakarta.ws.rs.BeanParam;
4+
import jakarta.ws.rs.GET;
5+
import jakarta.ws.rs.Path;
6+
7+
import org.jboss.shrinkwrap.api.ShrinkWrap;
8+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
9+
import org.junit.jupiter.api.Assertions;
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.extension.RegisterExtension;
12+
13+
import io.quarkus.test.QuarkusUnitTest;
14+
15+
public class EmptyBeanParamRecordTest {
16+
@RegisterExtension
17+
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
18+
.setArchiveProducer(() -> {
19+
return ShrinkWrap.create(JavaArchive.class)
20+
.addClasses(EmptyBeanParam.class, Resource.class);
21+
}).assertException(x -> {
22+
x.printStackTrace();
23+
Assertions.assertEquals(
24+
"Body parameters (or non-annotated fields) are not allowed for records. Make sure to annotate your record components with @Rest* or @*Param or that they can be injected as context objects.",
25+
x.getMessage());
26+
});
27+
28+
@Test
29+
void empty() {
30+
Assertions.fail();
31+
}
32+
33+
public record EmptyBeanParam(String something, Integer other) {
34+
}
35+
36+
@Path("/")
37+
public static class Resource {
38+
39+
@Path("/record")
40+
@GET
41+
public String beanParamRecord(@BeanParam EmptyBeanParam param) {
42+
return "OK";
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package io.quarkus.resteasy.reactive.server.test.beanparam;
2+
3+
import jakarta.ws.rs.BeanParam;
4+
import jakarta.ws.rs.GET;
5+
import jakarta.ws.rs.Path;
6+
7+
import org.jboss.shrinkwrap.api.ShrinkWrap;
8+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
9+
import org.junit.jupiter.api.Assertions;
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.extension.RegisterExtension;
12+
13+
import io.quarkus.test.QuarkusUnitTest;
14+
15+
public class ReallyEmptyBeanParamRecordTest {
16+
@RegisterExtension
17+
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
18+
.setArchiveProducer(() -> {
19+
return ShrinkWrap.create(JavaArchive.class)
20+
.addClasses(EmptyBeanParam.class, Resource.class);
21+
}).assertException(x -> {
22+
x.printStackTrace();
23+
Assertions.assertEquals(
24+
"No annotations found on fields at 'io.quarkus.resteasy.reactive.server.test.beanparam.ReallyEmptyBeanParamRecordTest$EmptyBeanParam'. Annotations like `@QueryParam` should be used in fields, not in methods.",
25+
x.getMessage());
26+
});
27+
28+
@Test
29+
void empty() {
30+
Assertions.fail();
31+
}
32+
33+
// This one does not even have body params
34+
public record EmptyBeanParam() {
35+
}
36+
37+
@Path("/")
38+
public static class Resource {
39+
40+
@Path("/record")
41+
@GET
42+
public String beanParamRecord(@BeanParam EmptyBeanParam param) {
43+
return "OK";
44+
}
45+
}
46+
}

independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/ServerEndpointIndexer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ protected InjectableBean scanInjectableBean(ClassInfo currentClassInfo, ClassInf
395395
annotations, field.type(), "%s", new Object[] { field }, applyFieldRules, hasRuntimeConverters,
396396
// We don't support annotation-less path params in injectable beans: only annotations
397397
Collections.emptySet(), field.name(), EMPTY_STRING_ARRAY, new HashMap<>());
398+
if (currentClassInfo.isRecord() && result.getType() == ParameterType.BODY) {
399+
throw new DeploymentException(
400+
"Body parameters (or non-annotated fields) are not allowed for records. Make sure to annotate your record components with @Rest* or @*Param or that they can be injected as context objects.");
401+
}
398402
if ((result.getType() != null) && (result.getType() != ParameterType.BEAN)) {
399403
//BODY means no annotation, so for fields not injectable
400404
fieldExtractors.put(field, result);

0 commit comments

Comments
 (0)