stanfordnlp/CoreNLP · error · RuntimeException
java.lang.CloneNotSupportedException
Error message
java.lang.CloneNotSupportedException
What it means
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.
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()
Example fix
// before
class MyTemporal extends SUTime.Temporal { ... }
// after
class MyTemporal extends SUTime.Temporal implements Cloneable {
@Override public MyTemporal clone() { return (MyTemporal) super.clone(); }
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!(temporal instanceof Cloneable)) { throw new IllegalStateException("Temporal subclass must implement Cloneable"); } Type guard
boolean isCloneableTemporal(SUTime.Temporal t) { return t instanceof Cloneable; } Try / catch
try { t = temporal.addMod(mod); } catch (RuntimeException e) { if (e.getCause() instanceof CloneNotSupportedException) { /* rebuild temporal manually */ } else throw e; } Prevention
- Always implement Cloneable when extending SUTime.Temporal
- Override clone() with a public, non-throwing version
- Test addMod/addModApprox paths for custom Temporals
When it happens
Trigger: Calling addMod/addModApprox (directly or via SUTime temporal expression resolution) on a custom Temporal subclass that extends SUTime.Temporal without implementing Cloneable.
Common situations: Users extending SUTime.Temporal to model custom temporal types and forgetting to implement Cloneable/override clone(); almost never triggered by stock CoreNLP classes.
Related errors
- Cannot cast " + classname + " into " + type.getName()
- Cannot cast to type (unhandled type): " + type
- Cannot convert type to class: " + type
- Cannot get field from
- Caught bad number:
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/9a18ce3a59ab82f4.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/time/SUTime.java:553
public/* abstract*/Temporal intersect(Temporal t) {
return null;
}
public String getMod() {
return mod;
}
/* public void setMod(String mod) {
this.mod = mod;
} */
public Temporal addMod(String mod) {
try {
Temporal t = (Temporal) this.clone();
t.mod = mod;
return t;
} catch (CloneNotSupportedException ex) {
throw new RuntimeException(ex);
}
}
public Temporal addModApprox(String mod, boolean approx) {
try {
Temporal t = (Temporal) this.clone();
t.mod = mod;
t.approx = approx;
return t;
} catch (CloneNotSupportedException ex) {
throw new RuntimeException(ex);
}
}
private static final long serialVersionUID = 1;
}
public static <T extends Temporal> T createTemporal(StandardTemporalType timeType, T temporal) {View on GitHub (pinned to 1b7edd19c4)