deeplearning4j/deeplearning4j · error · java.lang.IllegalArgumentException
No constructor found with parameter count < 3 for op
Error message
No constructor found with parameter count < 3 for op ${declaration.opName} What it means
AbstractMappingProcessLoader.createProcess instantiates a mapping-process rule instance reflectively, matching a declared constructor with fewer than 3 parameters. When the rule class registered for an op declaration exposes no such constructor, it cannot be built from the mapper declaration alone, so the loader throws this IllegalArgumentException in its `else` branch. It means the import rule class's constructor signature does not match what the framework-import loader protocol expects.
Solutions
- Change the rule class to declare a constructor with fewer than 3 parameters (e.g. only opName and inputFrameworkOpName, or a no-arg constructor) so the loader can instantiate it reflectively.
- Check which constructor arity the loader dispatch actually supports in AbstractMappingProcessLoader and match your rule class to one of the supported `when` branches.
- If extra parameters are needed, set them after construction (setters/lateinit) rather than via the constructor.
- Verify you did not hand-edit or mismatch the generated mapper declaration (declaration.opName) against the rule class it maps to.
Example fix
// before
class MyOpMappingRule(
val opName: String,
val inputFrameworkOpName: String,
val extraConfig: String
) : TensorMappingRule<...>()
// after
class MyOpMappingRule(
val opName: String,
val inputFrameworkOpName: String
) : TensorMappingRule<...>() {
lateinit var extraConfig: String
} Defensive patterns
Strategy: validation
Validate before calling
// Kotlin
fun hasShortConstructor(clazz: Class<*>) =
clazz.constructors.any { it.parameterCount < 3 }
require(hasShortConstructor(ruleClass)) { "Rule class ${ruleClass.name} needs a constructor with < 3 params" } Type guard
fun <T : Any> Class<T>.isLoaderInstantiable(): Boolean =
this.constructors.any { it.parameterCount < 3 } Prevention
- Keep custom mapping rule classes to the canonical (opName, inputFrameworkOpName) constructor signature.
- Inject extra dependencies via setters or DI after instantiation, not constructor parameters.
- Load all mapper declarations in a test early so bad rule classes fail at build time, not import time.
When it happens
Trigger: Calling createProcess (or a loader path that reaches it, e.g. when loading mapper declarations from a generated import project) where the `when(instance)`/constructor-dispatch falls through to `else` for a rule class whose constructor has 3 or more parameters or no matching accessible constructor for declaration.opName.
Common situations: Writing a custom TensorOp/OpMapper rule class with extra constructor parameters (e.g. injecting extra config) instead of the expected (opName, inputFrameworkOpName[, inputFrameworkOpDef]) signature; changing a rule's constructor during a refactor; copying a rule class from a newer/older import-framework version with a different constructor contract.
Related errors
- Cannot find no-arg constructor for class " + writableClass
- Class [ ] must have public constructor in order to be…
- Illegal type
- Individual arguments must not be null
- No constructor found with parameter count < 3! Rule name
AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07).
Data as JSON: /api/errors/904cd32150542e8b.
Report an issue: GitHub.
Appendix: source
Thrown at nd4j/samediff-import/samediff-import-api/src/main/kotlin/org/nd4j/samediff/frameworkimport/process/AbstractMappingProcessLoader.kt:137
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)
listOfAttributeRules.add(instance)
}
else -> {
throw IllegalArgumentException("No constructor found with parameter count < 3 for op " + declaration.opName)
}
}
}
}
}
val indexOverridesConverted = HashMap<Int,Int>()
declaration.indexOverridesMap.forEach { (input, output) ->
indexOverridesConverted[input.toInt()] = output.toInt()
}
return instantiateMappingProcess(
inputFrameworkOpName = declaration.inputFrameworkOpName,
opName = declaration.opName,View on GitHub (pinned to 4c22ac5fe4)