{"record":{"id":"9a18ce3a59ab82f4","repo":"stanfordnlp/CoreNLP","slug":"java-lang-clonenotsupportedexception","errorCode":null,"errorMessage":"java.lang.CloneNotSupportedException","messagePattern":"java\\.lang\\.CloneNotSupportedException","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/time/SUTime.java","lineNumber":553,"sourceCode":"    public/* abstract*/Temporal intersect(Temporal t) {\n      return null;\n    }\n\n    public String getMod() {\n      return mod;\n    }\n\n    /*   public void setMod(String mod) {\n         this.mod = mod;\n       } */\n\n    public Temporal addMod(String mod) {\n      try {\n        Temporal t = (Temporal) this.clone();\n        t.mod = mod;\n        return t;\n      } catch (CloneNotSupportedException ex) {\n        throw new RuntimeException(ex);\n      }\n    }\n\n    public Temporal addModApprox(String mod, boolean approx) {\n      try {\n        Temporal t = (Temporal) this.clone();\n        t.mod = mod;\n        t.approx = approx;\n        return t;\n      } catch (CloneNotSupportedException ex) {\n        throw new RuntimeException(ex);\n      }\n    }\n\n    private static final long serialVersionUID = 1;\n  }\n\n  public static <T extends Temporal> T createTemporal(StandardTemporalType timeType, T temporal) {","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/time/SUTime.java#L535-L571","documentation":"SUTime.Temporal.addMod() clones the Temporal via Object.clone() and wraps any CloneNotSupportedException in a RuntimeException. The clone fails only if the concrete Temporal subclass does not implement Cloneable, which would be a library-internal bug since all shipped subclasses do. Developers see this as a wrapped RuntimeException whose cause is java.lang.CloneNotSupportedException.","triggerScenarios":"Calling addMod/addModApprox (directly or via SUTime temporal expression resolution) on a custom Temporal subclass that extends SUTime.Temporal without implementing Cloneable.","commonSituations":"Users extending SUTime.Temporal to model custom temporal types and forgetting to implement Cloneable/override clone(); almost never triggered by stock CoreNLP classes.","solutions":["Make your Temporal subclass implement Cloneable and override clone() to be public and not throw","Check the wrapped cause in the RuntimeException stack trace to identify which class failed to clone","Upgrade CoreNLP if the error occurs with a stock Temporal subclass (internal bug)","As a workaround, construct a new Temporal and copy fields instead of relying on clone()"],"exampleFix":"// before\nclass MyTemporal extends SUTime.Temporal { ... }\n// after\nclass MyTemporal extends SUTime.Temporal implements Cloneable {\n  @Override public MyTemporal clone() { return (MyTemporal) super.clone(); }\n}","handlingStrategy":"try-catch","validationCode":"if (!(temporal instanceof Cloneable)) { throw new IllegalStateException(\"Temporal subclass must implement Cloneable\"); }","typeGuard":"boolean isCloneableTemporal(SUTime.Temporal t) { return t instanceof Cloneable; }","tryCatchPattern":"try { t = temporal.addMod(mod); } catch (RuntimeException e) { if (e.getCause() instanceof CloneNotSupportedException) { /* rebuild temporal manually */ } else throw e; }","preventionTips":["Always implement Cloneable when extending SUTime.Temporal","Override clone() with a public, non-throwing version","Test addMod/addModApprox paths for custom Temporals"],"tags":["java","clone","reflection","sutime"],"backgroundTag":"class-not-found","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}