OpenFeign/feign · error · IllegalStateException
Cannot find any suitable constructor in class
Error message
Cannot find any suitable constructor in class [${exceptionClass}] - did you forget to mark one with @FeignExceptionConstructor or at least have a public default constructor? What it means
Thrown by ExceptionGenerator.getConstructor when the exception class has no constructor marked with @FeignExceptionConstructor and also no public no-arg constructor accessible via getConstructor(). Feign needs an invokable constructor to instantiate the configured exception type.
Solutions
- Annotate one suitable constructor with @FeignExceptionConstructor
- Add a public no-arg constructor to the exception class
- Make the existing no-arg constructor public
Example fix
// before
public class ApiError extends RuntimeException {
public ApiError(int status, String body) { ... } // no default ctor, none annotated
}
// after
public class ApiError extends RuntimeException {
@FeignExceptionConstructor
public ApiError(int status, String body) { ... }
} Defensive patterns
Strategy: validation
Validate before calling
boolean ok = Arrays.stream(ApiError.class.getConstructors())
.anyMatch(c -> c.isAnnotationPresent(FeignExceptionConstructor.class))
|| Arrays.stream(ApiError.class.getConstructors())
.anyMatch(c -> c.getParameterCount() == 0);
if (!ok) throw new IllegalStateException("Needs @FeignExceptionConstructor or public default ctor"); Try / catch
try { Feign.builder().build(); }
catch (IllegalStateException e) { if (e.getMessage().startsWith("Cannot find any suitable constructor")) { ... } } Prevention
- Always mark one constructor with @FeignExceptionConstructor when using constructor args
- Remember Lombok @Builder / explicit constructors remove the implicit default constructor
- Keep the exception class and constructor public
When it happens
Trigger: Configuring a custom exception class that has only constructors with parameters, none annotated with @FeignExceptionConstructor; or a no-arg constructor that is private/protected/package-private.
Common situations: Using Lombok @Builder or a convenience multi-arg constructor which removes the implicit default constructor; exception class written for a different framework; non-public constructor added for encapsulation.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Cannot generate exception - check constructor parameter…
- Too many constructors marked with @FeignExceptionConstructor
- Cannot access constructor
- Cannot instantiate exception with constructor
- Cannot invoke constructor
AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10).
Data as JSON: /api/errors/317a21dc7717a841.
Report an issue: GitHub.
Appendix: source
Thrown at annotation-error-decoder/src/main/java/feign/error/ExceptionGenerator.java:232
continue;
}
Class<?>[] parameterTypes = constructor.getParameterTypes();
if (parameterTypes.length == 0) {
continue;
}
if (preferredConstructor == null) {
preferredConstructor = (Constructor<? extends Exception>) constructor;
} else {
throw new IllegalStateException(
"Too many constructors marked with @FeignExceptionConstructor");
}
}
if (preferredConstructor == null) {
try {
return exceptionClass.getConstructor();
} catch (NoSuchMethodException e) {
throw new IllegalStateException(
"Cannot find any suitable constructor in class ["
+ exceptionClass.getName()
+ "] - did you forget to mark one with @FeignExceptionConstructor or at least"
+ " have a public default constructor?",
e);
}
}
return preferredConstructor;
}
}
}
View on GitHub (pinned to e2a1e27560)