quarkusio/quarkus · error · RuntimeException
Method '${info.name()} of class '${info.declaringClass().nam
Error message
Method '${info.name()} of class '${info.declaringClass().name()}' cannot be private as it is annotated with '@jakarta.ws.rs.ext.Provider' What it means
checkModifiers in ServerExceptionMapperGenerator rejects exception mapper methods declared private. A method annotated with @jakarta.ws.rs.ext.Provider (or @ServerExceptionMapper) must be non-private because the generated filter/interceptor code invokes it reflectively/via bytecode generated at build time, which requires accessible methods.
Source
Thrown at independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/generation/exceptionmappers/ServerExceptionMapperGenerator.java:640
return ReturnType.REST_RESPONSE;
} else if (targetMethod.returnType().kind() == Type.Kind.PARAMETERIZED_TYPE) {
ParameterizedType parameterizedType = targetMethod.returnType().asParameterizedType();
if (parameterizedType.name().equals(UNI) && (parameterizedType.arguments().size() == 1)) {
if (parameterizedType.arguments().get(0).name().equals(RESPONSE)) {
return ReturnType.UNI_RESPONSE;
}
if (parameterizedType.arguments().get(0).name().equals(REST_RESPONSE)) {
return ReturnType.UNI_REST_RESPONSE;
}
}
}
throw new RuntimeException("Method '" + targetMethod.name() + " of class '" + targetMethod.declaringClass().name()
+ "' cannot be used as an exception mapper as it does not declare 'Response' or 'Uni<Response>' or as its return type");
}
private static void checkModifiers(MethodInfo info) {
if ((info.flags() & Modifier.PRIVATE) != 0) {
throw new RuntimeException("Method '" + info.name() + " of class '" + info.declaringClass().name()
+ "' cannot be private as it is annotated with '@" + SERVER_EXCEPTION_MAPPER
+ "'");
}
if ((info.flags() & Modifier.STATIC) != 0) {
throw new RuntimeException("Method '" + info.name() + " of class '" + info.declaringClass().name()
+ "' cannot be static as it is annotated with '@" + SERVER_EXCEPTION_MAPPER
+ "'");
}
}
private static String getGeneratedClassName(MethodInfo targetMethod, Type handledExceptionType) {
return targetMethod.declaringClass().name() + "$ExceptionMapper$"
+ HashUtil.sha1(targetMethod.name() + handledExceptionType.name().toString());
}
private enum ReturnType {
RESPONSE,
REST_RESPONSE,View on GitHub (pinned to e1c734241f)
Solutions
- Change the mapper method from private to at least package-private (recommended: public)
- Move the mapper to a dedicated @Provider class if visibility was intentional
- Remove the @Provider/@ServerExceptionMapper annotation if the method is not a mapper
Example fix
// before
@ServerExceptionMapper
private Response map(NotFoundException e) { ... }
// after
@ServerExceptionMapper
public Response map(NotFoundException e) { ... } Defensive patterns
Strategy: validation
Validate before calling
java.lang.reflect.Method m = ...; // annotated mapper
if (java.lang.reflect.Modifier.isPrivate(m.getModifiers())) {
throw new IllegalStateException("@ServerExceptionMapper methods must not be private: " + m);
}
Type guard
static boolean isAccessibleMapper(java.lang.reflect.Method m) {
return !java.lang.reflect.Modifier.isPrivate(m.getModifiers());
}
Prevention
- Declare exception mapper methods public by default
- Avoid IDE 'encapsulate' refactors on annotated methods
- Code-review visibility changes in classes containing @ServerExceptionMapper
When it happens
Trigger: A method carrying @ServerExceptionMapper or @Provider whose flags include Modifier.PRIVATE, detected during build-time generation of the exception mapper class.
Common situations: Keeping mapper methods private inside a resource or provider class, IDE auto-generating the method as private, or narrowing visibility during refactoring.
Related errors
- The combination of '@${annotationName}' and '@ServerExceptio
- Method '${targetMethod.name()} of class '${targetMethod.decl
- Method '${info.name()} of class '${info.declaringClass().nam
- Method '${info.name()} of class '${info.declaringClass().nam
- Could not load exception mapper
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/744aa5e376436e04.
Report an issue: GitHub.