{"record":{"id":"805542bae0dd2e53","repo":"deeplearning4j/deeplearning4j","slug":"no-constructor-found-with-parameter-count-3-rul","errorCode":null,"errorMessage":"No constructor found with parameter count < 3! Rule name ${rule.ruleName}","messagePattern":"No constructor found with parameter count < 3! Rule name (.+?)","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"nd4j/samediff-import/samediff-import-api/src/main/kotlin/org/nd4j/samediff/frameworkimport/process/AbstractMappingProcessLoader.kt","lineNumber":115,"sourceCode":"                \"tensor\" -> {\n                    val clazz = tensorRuleRegistry()[rule.ruleName]!!.getConstructor(dictClass,transformerArgsClass)\n                    val transformerArgs = ConcurrentHashMap<String,List<OpNamespace.ArgDescriptor>>()\n                    rule.transformerArgsList.forEach { arg ->\n                        transformerArgs[arg.key] = arg.transformerArgsList\n                    }\n\n                    val instance = clazz.newInstance(rule.inputToOutputMap,transformerArgs)\n                    listOfTensorRules.add(instance)\n\n                }\n                \"attribute\" -> {\n                    val transformerArgs = ConcurrentHashMap<String,List<OpNamespace.ArgDescriptor>>()\n                    rule.transformerArgsList.forEach { arg ->\n                        transformerArgs[arg.key] = arg.transformerArgsList\n                    }\n\n                    val constructor = attributeRuleRegistry()[rule.ruleName]!!.constructors.firstOrNull { constructor -> constructor.parameterCount == 1 || constructor.parameterCount == 2\n                    } ?: throw IllegalArgumentException(\"No constructor found with parameter count < 3! Rule name ${rule.ruleName}\")\n\n\n                    when (constructor!!.parameterCount) {\n                        1 -> {\n                            val instance = constructor!!.newInstance(rule.inputToOutputMap) as AttributeMappingRule<GRAPH_TYPE, OP_DEF_TYPE, NODE_DEF_TYPE, ATTRIBUTE_TYPE, ATTRIBUTE_VALUE_TYPE, TENSOR_TYPE, DATA_TYPE>\n                            instance.setMappingTransformerArgs(transformerArgs)\n                            instance.setMappingTransformerArgs(transformerArgs)\n                            instance.modifyName(rule.ruleName)\n                            instance.modifyInputFrameworkOpName(rule.inputFrameworkOpName)\n                            listOfAttributeRules.add(instance)\n                        }\n                        2 -> {\n                            val instance = constructor.newInstance(rule.inputToOutputMap,transformerArgs) as AttributeMappingRule<GRAPH_TYPE, OP_DEF_TYPE, NODE_DEF_TYPE, ATTRIBUTE_TYPE, ATTRIBUTE_VALUE_TYPE, TENSOR_TYPE, DATA_TYPE>\n\n                            instance.setMappingTransformerArgs(transformerArgs)\n                            instance.modifyName(rule.ruleName)\n                            instance.modifyInputFrameworkOpName(rule.inputFrameworkOpName)\n","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/nd4j/samediff-import/samediff-import-api/src/main/kotlin/org/nd4j/samediff/frameworkimport/process/AbstractMappingProcessLoader.kt#L97-L133","documentation":"Thrown by AbstractMappingProcessLoader.createProcess when instantiating an AttributeMappingRule from a serialized rule definition. It looks up the rule class in attributeRuleRegistry() and searches for a constructor with 1 or 2 parameters; if the registered class has no such constructor (parameterCount >= 3 or zero), it throws IllegalArgumentException naming the rule.","triggerScenarios":"Loading a mapping process from a serialized config (e.g. protocol-buffer-defined process files) where rule.ruleName resolves to a class whose constructors all take >= 3 arguments, or the registry maps the rule name to the wrong class.","commonSituations":"Adding a custom AttributeMappingRule with a multi-arg constructor and registering it without a 1- or 2-arg constructor; rule name collision causing the registry to resolve a different class; stale/mismatched generated rule registry after refactor; loading old serialized configs against new rule classes.","solutions":["Add a 1- or 2-parameter constructor to the rule class (Kotlin primary constructor with only inputToOutputMap, plus optional second param) so the loader can instantiate it.","Check attributeRuleRegistry() to confirm rule.ruleName maps to the intended class, not a same-named different rule.","If a custom rule needs more config, keep the small constructor and supply the rest via setMappingTransformerArgs / transformer args.","Regenerate the rule registry after refactoring rule classes so names and classes stay in sync."],"exampleFix":"// before\nclass MyRule(val map: Map<String,String>, val ctx: Context, val flag: Boolean) : AttributeMappingRule<...>\n// after\nclass MyRule(val map: Map<String,String>) : AttributeMappingRule<...> { ... } // <=2 param constructor for loader reflection","handlingStrategy":"try-catch","validationCode":"val cls = attributeRuleRegistry()[rule.ruleName]\nrequireNotNull(cls) { \"Rule ${rule.ruleName} not registered\" }\nrequire(cls.constructors.any { it.parameterCount == 1 || it.parameterCount == 2 }) {\n    \"Rule ${rule.ruleName} needs a 1- or 2-parameter constructor\"\n}","typeGuard":null,"tryCatchPattern":"try {\n    loader.createProcess(...)\n} catch (e: IllegalArgumentException) {\n    if (e.message?.contains(\"No constructor found\") == true) throw IllegalStateException(\"Rule class incompatible with loader: ${e.message}\", e) else throw e\n}","preventionTips":["Give every custom AttributeMappingRule a primary constructor of at most 2 parameters.","Pass extra configuration via setMappingTransformerArgs instead of constructor arguments.","Keep the rule-name-to-class registry generated/updated in the same change as rule class refactors."],"tags":["kotlin","reflection","nd4j","model-import"],"backgroundTag":"missing-required-argument","analyzedSha":"4c22ac5fe4a8350d05d224e7f4499429f7f69c93","analyzedAt":"2026-09-07T05:27:04.714Z","contentChangedAt":"2026-09-07T05:27:04.714Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}