{"record":{"id":"f9447ce10f5f9b53","repo":"clojure/clojure","slug":"no-matching-ctor-found-for","errorCode":null,"errorMessage":"No matching ctor found for ","messagePattern":"No matching ctor found for ","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/jvm/clojure/lang/Compiler.java","lineNumber":3106,"sourceCode":"\tpublic NewExpr(Class c, IPersistentVector args, int line, int column) {\n\t\tthis.args = args;\n\t\tthis.c = c;\n\t\tConstructor[] allctors = c.getConstructors();\n\t\tArrayList ctors = new ArrayList();\n\t\tArrayList<Class[]> params = new ArrayList();\n\t\tArrayList<Class> rets = new ArrayList();\n\t\tfor(int i = 0; i < allctors.length; i++)\n\t\t\t{\n\t\t\tConstructor ctor = allctors[i];\n\t\t\tif(ctor.getParameterTypes().length == args.count())\n\t\t\t\t{\n\t\t\t\tctors.add(ctor);\n\t\t\t\tparams.add(ctor.getParameterTypes());\n\t\t\t\trets.add(c);\n\t\t\t\t}\n\t\t\t}\n\t\tif(ctors.isEmpty())\n\t\t\tthrow new IllegalArgumentException(\"No matching ctor found for \" + c);\n\n\t\tint ctoridx = 0;\n\t\tif(ctors.size() > 1)\n\t\t\t{\n\t\t\tctoridx = getMatchingParams(c.getName(), params, args, rets);\n\t\t\t}\n\n\t\tthis.ctor = ctoridx >= 0 ? (Constructor) ctors.get(ctoridx) : null;\n\t\tif(ctor == null && RT.booleanCast(RT.WARN_ON_REFLECTION.deref()))\n\t\t\t{\n\t\t\tRT.errPrintWriter()\n              .format(\"Reflection warning, %s:%d:%d - call to %s ctor can't be resolved.\\n\",\n                      SOURCE_PATH.deref(), line, column, c.getName());\n\t\t\t}\n\t}\n\n\tpublic Object eval() {\n\t\tObject[] argvals = new Object[args.count()];","sourceCodeStart":3088,"sourceCodeEnd":3124,"githubUrl":"https://github.com/clojure/clojure/blob/f3b143341d6efc6428b523b2eaa099a6cc99156e/src/jvm/clojure/lang/Compiler.java#L3088-L3124","documentation":"NewExpr filters c.getConstructors() by argument count; if no public constructor takes exactly args.count() parameters, compilation of the (new C ...) form is aborted. Fires when the argument arity matches no public constructor — wrong arg count, or the matching constructor is not public.","triggerScenarios":"(new Foo 1 2) when Foo has no two-arg constructor; passing wrong arity or types so no ctor's parameter list matches after argcount filtering and matching.","commonSituations":"Mismatches between documented and actual constructor arity after library upgrades; calling (Foo.) on classes with required args; typed args not matching any overload due to nil or wrong boxed types.","solutions":["Check the class's available constructors and match arity and types","Use type hints/casts so argument types match a constructor signature","Verify the class name resolves to the intended class","Consult javadoc for required constructor parameters"],"exampleFix":";; before\n(new StringBuilder 42)\n;; after\n(new StringBuilder (str 42))","handlingStrategy":"validation","validationCode":"(defn ctor-arity-ok? [cls n]\n  (some #(= n (count (.getParameterTypes ^java.lang.reflect.Constructor %)))\n        (.getDeclaredConstructors cls)))","typeGuard":null,"tryCatchPattern":"(try (new Foo 1 2)\n  (catch IllegalArgumentException e\n    (when (.startsWith (.getMessage e) \"No matching ctor\")\n      (println \"check ctor signature:\" (.getMessage e)))))","preventionTips":["Verify constructor arity/types against javadoc before calling","Check signatures after upgrading Java libraries","Cast/type-hint args so they match an overload"],"tags":["clojure","reflection","java-interop","constructor"],"backgroundTag":"no-matching-constructor","analyzedSha":"f3b143341d6efc6428b523b2eaa099a6cc99156e","analyzedAt":"2026-09-09T12:04:58.961Z","contentChangedAt":"2026-09-09T12:04:58.961Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}