Skip to content

Commit a866ec4

Browse files
committed
Improve error message when @BeanParam class has no fields
Co-authored-by: Stéphane Épardaud <[email protected]> Closes: #47545
1 parent 2aa50b9 commit a866ec4

File tree

1 file changed

+10
-3
lines changed
  • independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,16 @@ protected boolean handleBeanParam(ClassInfo actualEndpointInfo, Type paramType,
300300
actualEndpointInfo,
301301
existingConverters, additionalReaders, injectableBeans, hasRuntimeConverters);
302302
if ((injectableBean.getFieldExtractorsCount() == 0) && !injectableBean.isInjectionRequired()) {
303-
throw new DeploymentException(String.format("No annotations found on fields at '%s'. "
304-
+ "Annotations like `@QueryParam` should be used in fields, not in methods.",
305-
beanParamClassInfo.name()));
303+
long declaredMethodsCount = beanParamClassInfo.methods().stream()
304+
.filter(m -> !m.name().equals("<init>") && !m.name().equals("<clinit>")).count();
305+
if (declaredMethodsCount == 0) {
306+
throw new DeploymentException(String.format("Class %s has no fields. Parameters containers are only supported if they have at least one annotated field.", beanParamClassInfo.name()));
307+
} else {
308+
throw new DeploymentException(String.format("No annotations found on fields at '%s'. "
309+
+ "Annotations like `@QueryParam` should be used in fields, not in methods.",
310+
beanParamClassInfo.name()));
311+
}
312+
306313
}
307314
fileFormNames.addAll(injectableBean.getFileFormNames());
308315
return injectableBean.isFormParamRequired();

0 commit comments

Comments
 (0)