{"record":{"id":"03e3b8c746dffbfe","repo":"pentaho/pentaho-kettle","slug":"unable-to-clone-import-rule","errorCode":null,"errorMessage":"Unable to clone import rule","messagePattern":"Unable to clone import rule","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/imp/rules/BaseImportRule.java","lineNumber":45,"sourceCode":"import org.w3c.dom.Node;\n\npublic abstract class BaseImportRule implements ImportRuleInterface {\n\n  public static String XML_TAG = \"rule\";\n\n  private String id;\n  private boolean enabled;\n\n  public BaseImportRule() {\n    this.enabled = false;\n  }\n\n  @Override\n  public ImportRuleInterface clone() {\n    try {\n      return (ImportRuleInterface) super.clone();\n    } catch ( CloneNotSupportedException e ) {\n      throw new RuntimeException( \"Unable to clone import rule\", e );\n    }\n  }\n\n  @Override\n  public boolean isUnique() {\n    return true;\n  }\n\n  @Override\n  public abstract List<ImportValidationFeedback> verifyRule( Object subject );\n\n  @Override\n  public String getXML() {\n    StringBuilder xml = new StringBuilder();\n\n    xml.append( XMLHandler.addTagValue( \"id\", id ) );\n    xml.append( XMLHandler.addTagValue( \"enabled\", enabled ) );\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/imp/rules/BaseImportRule.java#L27-L63","documentation":"BaseImportRule.clone() overrides Object.clone() to copy import rules; since CloneNotSupportedException is checked and the interface contract expects clonability, it rethrows it as a RuntimeException \"Unable to clone import rule\" with the cause attached. Reaching it means a rule subclass somehow inherited clone support incorrectly (effectively an internal invariant violation).","triggerScenarios":"Calling clone() (directly or via ImportRules copy/duplicate operations) on a rule whose class hierarchy does not properly support cloning — e.g. a subclass not implementing Clonenable transitively or super.clone() failing in a custom rule implementation.","commonSituations":"Custom import rule plugins that override clone or reshape the hierarchy without honoring the Cloneable contract; classloader/version mixing where the rule class was loaded in a way that broke the standard clone path.","solutions":["Ensure your rule class (and BaseImportRule hierarchy) implements java.lang.Cloneable.","Inspect getCause() (CloneNotSupportedException) to identify which class in the hierarchy is not cloneable.","In a custom rule, override clone() to use super.clone() and implement Cloneable rather than replacing the mechanism.","As a workaround, perform a deep copy by re-creating the rule and copying its fields instead of relying on clone()."],"exampleFix":"// before\npublic class MyRule extends BaseImportRule { // no Cloneable handling\n  public MyRule copy() { return (MyRule) clone(); }\n}\n// after\npublic class MyRule extends BaseImportRule implements Cloneable {\n  public MyRule copy() { return (MyRule) super.clone(); }\n}","handlingStrategy":"try-catch","validationCode":"if (!(rule instanceof Cloneable)) {\n  throw new IllegalStateException(\"Rule must implement Cloneable to be copied\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  ImportRuleInterface copy = rule.clone();\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Unable to clone\")) {\n    log.error(\"Rule class does not support cloning: \" + rule.getClass().getName(), e.getCause());\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always implement Cloneable in custom rule subclasses","Keep super.clone() as the copy mechanism in overrides","Inspect getCause() when clone fails to find the offending class"],"tags":["clone","cloneable","internal-invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}