{"record":{"id":"317a21dc7717a841","repo":"OpenFeign/feign","slug":"cannot-find-any-suitable-constructor-in-class-e","errorCode":null,"errorMessage":"Cannot find any suitable constructor in class [${exceptionClass}] - did you forget to mark one with @FeignExceptionConstructor or at least have a public default constructor?","messagePattern":"Cannot find any suitable constructor in class \\[(.+?)\\] - did you forget to mark one with @FeignExceptionConstructor or at least have a public default constructor\\?","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"annotation-error-decoder/src/main/java/feign/error/ExceptionGenerator.java","lineNumber":232,"sourceCode":"          continue;\n        }\n        Class<?>[] parameterTypes = constructor.getParameterTypes();\n        if (parameterTypes.length == 0) {\n          continue;\n        }\n        if (preferredConstructor == null) {\n          preferredConstructor = (Constructor<? extends Exception>) constructor;\n        } else {\n          throw new IllegalStateException(\n              \"Too many constructors marked with @FeignExceptionConstructor\");\n        }\n      }\n\n      if (preferredConstructor == null) {\n        try {\n          return exceptionClass.getConstructor();\n        } catch (NoSuchMethodException e) {\n          throw new IllegalStateException(\n              \"Cannot find any suitable constructor in class [\"\n                  + exceptionClass.getName()\n                  + \"] - did you forget to mark one with @FeignExceptionConstructor or at least\"\n                  + \" have a public default constructor?\",\n              e);\n        }\n      }\n      return preferredConstructor;\n    }\n  }\n}\n","sourceCodeStart":214,"sourceCodeEnd":244,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/annotation-error-decoder/src/main/java/feign/error/ExceptionGenerator.java#L214-L244","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Annotate one suitable constructor with @FeignExceptionConstructor","Add a public no-arg constructor to the exception class","Make the existing no-arg constructor public"],"exampleFix":"// before\npublic class ApiError extends RuntimeException {\n  public ApiError(int status, String body) { ... } // no default ctor, none annotated\n}\n// after\npublic class ApiError extends RuntimeException {\n  @FeignExceptionConstructor\n  public ApiError(int status, String body) { ... }\n}","handlingStrategy":"validation","validationCode":"boolean ok = Arrays.stream(ApiError.class.getConstructors())\n    .anyMatch(c -> c.isAnnotationPresent(FeignExceptionConstructor.class))\n  || Arrays.stream(ApiError.class.getConstructors())\n    .anyMatch(c -> c.getParameterCount() == 0);\nif (!ok) throw new IllegalStateException(\"Needs @FeignExceptionConstructor or public default ctor\");","typeGuard":null,"tryCatchPattern":"try { Feign.builder().build(); }\ncatch (IllegalStateException e) { if (e.getMessage().startsWith(\"Cannot find any suitable constructor\")) { ... } }","preventionTips":["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"],"tags":["java","feign","reflection","missing-constructor"],"backgroundTag":"missing-required-argument","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"}