stanfordnlp/CoreNLP · error · IllegalArgumentException
Invalid timex xml
Error message
Invalid timex xml: ${xml} What it means
Thrown by Timex.fromXml when the input XML is not parseable as a TIMEX3 element, so no Timex object can be initialized. The method expects XML containing a TIMEX3 tag with attributes like tid, type, and value.
Solutions
- Ensure the input is well-formed XML with a TIMEX3 root element.
- Unwrap enclosing TimeML markup and pass only the TIMEX3 element string.
- Catch the IllegalArgumentException and fall back to Timex.fromMap with the attributes extracted separately.
- Validate/repair XML entities (&, <) before calling.
Example fix
// before
Timex t = Timex.fromXml("<time value=2020-03-03/>");
// after
Timex t = Timex.fromXml("<TIMEX3 tid=\"t1\" type=\"DATE\" value=\"2020-03-03\"/>"); Defensive patterns
Strategy: try-catch
Validate before calling
static boolean isTimex3Xml(String xml) {
return xml != null && xml.trim().startsWith("<TIMEX3") && xml.trim().endsWith(">");
} Try / catch
try {
Timex t = Timex.fromXml(xml);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Invalid timex xml:")) {
// fall back to building from raw attributes
Timex t = Timex.fromMap(text, attrsMap);
return t;
} else throw e;
} Prevention
- Only feed Timex.fromXml output of Timex.toXml or genuine TIMEX3 elements.
- Escape &, <, > in attribute values before serializing.
- Prefer fromMap when attributes are available programmatically — no XML round-trip needed.
When it happens
Trigger: Calling Timex.fromXml(xml) with a non-TIMEX3 root (e.g. <time>), malformed XML, or an empty/blank string; also when the XML parses but does not yield the expected element the init path requires.
Common situations: Round-tripping Timex output through systems that rename or wrap the tag; feeding plain text or TimeML fragments truncated mid-tag; XML with unescaped entities.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Cannot interpret
- Cannot interpret for
- Illegal quantifier at beginning of pattern
- Invalid arguments to
- Bad process cp1252
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/b9cbc9a89ddc9d5b.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/time/Timex.java:329
element.setTextContent(text);
}
return element;
}
// Used to create timex from XML (mainly for testing)
public static Timex fromXml(String xml) {
Element element = XMLUtils.parseElement(xml);
if ("TIMEX3".equals(element.getNodeName())) {
Timex t = new Timex();
// t.init(xml, element);
// Doesn't preserve original input xml
// Will reorder attributes of xml so can match xml of test timex and actual timex
// (for which we can't control the order of the attributes now we don't use nu.xom...)
t.init(element);
return t;
} else {
throw new IllegalArgumentException("Invalid timex xml: " + xml);
}
}
public static Timex fromMap(String text, Map<String, String> map) {
try {
Element element = XMLUtils.createElement("TIMEX3");
for (Map.Entry<String, String> entry : map.entrySet()) {
if (entry.getValue() != null) {
element.setAttribute(entry.getKey(), entry.getValue());
}
}
element.setTextContent(text);
return new Timex(element);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
View on GitHub (pinned to 1b7edd19c4)