OpenFeign/feign · error · IllegalStateException
Constructor does not exist
Error message
Constructor does not exist
What it means
Thrown by MethodErrorHandler.createException when NoSuchMethodException is raised while reflectively constructing the mapped exception during response decoding. Means the constructor the generator resolved earlier is no longer available at instantiation time — practically, the exception type's constructor could not be invoked as resolved.
Solutions
- Ensure a single version of the annotation-error-decoder module and the exception classes on the classpath (check for shading/duplicates with mvn dependency:tree)
- Recompile/redeploy cleanly so the exception class and its constructor are consistent
- Define the exception with a public constructor and @FeignExceptionConstructor so lookup is unambiguous
Example fix
// pom.xml: exclude stale duplicate
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-annotation-error-decoder</artifactId>
<exclusions><exclusion>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-annotation-error-decoder</artifactId>
</exclusion></exclusions>
</dependency> Defensive patterns
Strategy: try-catch
Validate before calling
try {
ApiError.class.getConstructor();
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Constructor not resolvable in this classloader", e);
} Try / catch
try { api.call(); } catch (IllegalStateException e) {
if ("Constructor does not exist".equals(e.getMessage())) { log.warn("classloader/shading issue", e.getCause()); }
} Prevention
- Avoid shading/relocating exception classes shared with the decoder configuration
- Pin a single version of feign-annotation-error-decoder and rebuild after upgrades
- Beware duplicate jars in app-server classpaths; verify with mvn dependency:tree
When it happens
Trigger: Runtime/classloader mismatch where the exception class loaded differs from the one compiled against (e.g. shaded or relocated classes); programmatic ExceptionGenerator use passing a Constructor lookup that fails; unusual classloader setups (app servers, OSGi) with split classpaths.
Common situations: Hot-redeploy environments with stale class references; fat-jar shading moving exception classes; duplicate versions of the library on the classpath.
Related errors
- Cannot generate exception - check constructor parameter…
- Too many constructors marked with @FeignExceptionConstructor
- Cannot find any suitable constructor in class
- Cannot access constructor
- Cannot instantiate exception with constructor
AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10).
Data as JSON: /api/errors/33f8a99eeb3f1355.
Report an issue: GitHub.
Appendix: source
Thrown at annotation-error-decoder/src/main/java/feign/error/MethodErrorHandler.java:62
return methodLevelExceptionsByCode.get(response.status());
}
if (classLevelExceptionsByCode.containsKey(response.status())) {
return classLevelExceptionsByCode.get(response.status());
}
return defaultException;
}
protected Exception createException(ExceptionGenerator constructorDefinition, Response response) {
try {
return constructorDefinition.createException(response);
} catch (IllegalAccessException e) {
throw new IllegalStateException("Cannot access constructor", e);
} catch (InstantiationException e) {
throw new IllegalStateException("Cannot instantiate exception with constructor", e);
} catch (InvocationTargetException e) {
throw new IllegalStateException("Cannot invoke constructor", e);
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Constructor does not exist", e);
}
}
}
View on GitHub (pinned to e2a1e27560)