deeplearning4j/deeplearning4j · error · java.lang.IllegalArgumentException

No constructor found with parameter count < 3! Rule name

Error message

No constructor found with parameter count < 3! Rule name ${rule.ruleName}

What it means

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.

Solutions

  1. 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.
  2. Check attributeRuleRegistry() to confirm rule.ruleName maps to the intended class, not a same-named different rule.
  3. If a custom rule needs more config, keep the small constructor and supply the rest via setMappingTransformerArgs / transformer args.
  4. Regenerate the rule registry after refactoring rule classes so names and classes stay in sync.

Example fix

// before
class MyRule(val map: Map<String,String>, val ctx: Context, val flag: Boolean) : AttributeMappingRule<...>
// after
class MyRule(val map: Map<String,String>) : AttributeMappingRule<...> { ... } // <=2 param constructor for loader reflection
Defensive patterns

Strategy: try-catch

Validate before calling

val cls = attributeRuleRegistry()[rule.ruleName]
requireNotNull(cls) { "Rule ${rule.ruleName} not registered" }
require(cls.constructors.any { it.parameterCount == 1 || it.parameterCount == 2 }) {
    "Rule ${rule.ruleName} needs a 1- or 2-parameter constructor"
}

Try / catch

try {
    loader.createProcess(...)
} catch (e: IllegalArgumentException) {
    if (e.message?.contains("No constructor found") == true) throw IllegalStateException("Rule class incompatible with loader: ${e.message}", e) else throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07). Data as JSON: /api/errors/805542bae0dd2e53. Report an issue: GitHub.

Appendix: source

Thrown at nd4j/samediff-import/samediff-import-api/src/main/kotlin/org/nd4j/samediff/frameworkimport/process/AbstractMappingProcessLoader.kt:115

                "tensor" -> {
                    val clazz = tensorRuleRegistry()[rule.ruleName]!!.getConstructor(dictClass,transformerArgsClass)
                    val transformerArgs = ConcurrentHashMap<String,List<OpNamespace.ArgDescriptor>>()
                    rule.transformerArgsList.forEach { arg ->
                        transformerArgs[arg.key] = arg.transformerArgsList
                    }

                    val instance = clazz.newInstance(rule.inputToOutputMap,transformerArgs)
                    listOfTensorRules.add(instance)

                }
                "attribute" -> {
                    val transformerArgs = ConcurrentHashMap<String,List<OpNamespace.ArgDescriptor>>()
                    rule.transformerArgsList.forEach { arg ->
                        transformerArgs[arg.key] = arg.transformerArgsList
                    }

                    val constructor = attributeRuleRegistry()[rule.ruleName]!!.constructors.firstOrNull { constructor -> constructor.parameterCount == 1 || constructor.parameterCount == 2
                    } ?: throw IllegalArgumentException("No constructor found with parameter count < 3! Rule name ${rule.ruleName}")


                    when (constructor!!.parameterCount) {
                        1 -> {
                            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>
                            instance.setMappingTransformerArgs(transformerArgs)
                            instance.setMappingTransformerArgs(transformerArgs)
                            instance.modifyName(rule.ruleName)
                            instance.modifyInputFrameworkOpName(rule.inputFrameworkOpName)
                            listOfAttributeRules.add(instance)
                        }
                        2 -> {
                            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>

                            instance.setMappingTransformerArgs(transformerArgs)
                            instance.modifyName(rule.ruleName)
                            instance.modifyInputFrameworkOpName(rule.inputFrameworkOpName)

View on GitHub (pinned to 4c22ac5fe4)