{"record":{"id":"33f8a99eeb3f1355","repo":"OpenFeign/feign","slug":"constructor-does-not-exist","errorCode":null,"errorMessage":"Constructor does not exist","messagePattern":"Constructor does not exist","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"annotation-error-decoder/src/main/java/feign/error/MethodErrorHandler.java","lineNumber":62,"sourceCode":"      return methodLevelExceptionsByCode.get(response.status());\n    }\n    if (classLevelExceptionsByCode.containsKey(response.status())) {\n      return classLevelExceptionsByCode.get(response.status());\n    }\n    return defaultException;\n  }\n\n  protected Exception createException(ExceptionGenerator constructorDefinition, Response response) {\n    try {\n      return constructorDefinition.createException(response);\n    } catch (IllegalAccessException e) {\n      throw new IllegalStateException(\"Cannot access constructor\", e);\n    } catch (InstantiationException e) {\n      throw new IllegalStateException(\"Cannot instantiate exception with constructor\", e);\n    } catch (InvocationTargetException e) {\n      throw new IllegalStateException(\"Cannot invoke constructor\", e);\n    } catch (NoSuchMethodException e) {\n      throw new IllegalStateException(\"Constructor does not exist\", e);\n    }\n  }\n}\n","sourceCodeStart":44,"sourceCodeEnd":66,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/annotation-error-decoder/src/main/java/feign/error/MethodErrorHandler.java#L44-L66","documentation":"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.","triggerScenarios":"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.","commonSituations":"Hot-redeploy environments with stale class references; fat-jar shading moving exception classes; duplicate versions of the library on the classpath.","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"],"exampleFix":"// pom.xml: exclude stale duplicate\n<dependency>\n  <groupId>io.github.openfeign</groupId>\n  <artifactId>feign-annotation-error-decoder</artifactId>\n  <exclusions><exclusion>\n    <groupId>io.github.openfeign</groupId>\n    <artifactId>feign-annotation-error-decoder</artifactId>\n  </exclusion></exclusions>\n</dependency>","handlingStrategy":"try-catch","validationCode":"try {\n  ApiError.class.getConstructor();\n} catch (NoSuchMethodException e) {\n  throw new IllegalStateException(\"Constructor not resolvable in this classloader\", e);\n}","typeGuard":null,"tryCatchPattern":"try { api.call(); } catch (IllegalStateException e) {\n  if (\"Constructor does not exist\".equals(e.getMessage())) { log.warn(\"classloader/shading issue\", e.getCause()); }\n}","preventionTips":["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"],"tags":["java","feign","reflection","class-not-found"],"backgroundTag":"class-not-found","analyzedSha":"e2a1e27560a1e68840c34f031afca88b36096e30","analyzedAt":"2026-09-10T12:37:37.238Z","contentChangedAt":"2026-09-10T12:37:37.238Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}