{"record":{"id":"b9cbc9a89ddc9d5b","repo":"stanfordnlp/CoreNLP","slug":"invalid-timex-xml-xml","errorCode":null,"errorMessage":"Invalid timex xml: ${xml}","messagePattern":"Invalid timex xml: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/time/Timex.java","lineNumber":329,"sourceCode":"      element.setTextContent(text);\n    }\n    return element;\n  }\n\n  // Used to create timex from XML (mainly for testing)\n  public static Timex fromXml(String xml) {\n    Element element = XMLUtils.parseElement(xml);\n    if (\"TIMEX3\".equals(element.getNodeName())) {\n      Timex t = new Timex();\n//      t.init(xml, element);\n\n      // Doesn't preserve original input xml\n      // Will reorder attributes of xml so can match xml of test timex and actual timex\n      // (for which we can't control the order of the attributes now we don't use nu.xom...)\n      t.init(element);\n      return t;\n    } else {\n      throw new IllegalArgumentException(\"Invalid timex xml: \" + xml);\n    }\n  }\n\n  public static Timex fromMap(String text, Map<String, String> map) {\n    try {\n      Element element = XMLUtils.createElement(\"TIMEX3\");\n      for (Map.Entry<String, String> entry : map.entrySet()) {\n        if (entry.getValue() != null) {\n          element.setAttribute(entry.getKey(), entry.getValue());\n        }\n      }\n      element.setTextContent(text);\n      return new Timex(element);\n    } catch (Exception ex) {\n      throw new RuntimeException(ex);\n    }\n  }\n","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/time/Timex.java#L311-L347","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nTimex t = Timex.fromXml(\"<time value=2020-03-03/>\");\n\n// after\nTimex t = Timex.fromXml(\"<TIMEX3 tid=\\\"t1\\\" type=\\\"DATE\\\" value=\\\"2020-03-03\\\"/>\");","handlingStrategy":"try-catch","validationCode":"static boolean isTimex3Xml(String xml) {\n  return xml != null && xml.trim().startsWith(\"<TIMEX3\") && xml.trim().endsWith(\">\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  Timex t = Timex.fromXml(xml);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Invalid timex xml:\")) {\n    // fall back to building from raw attributes\n    Timex t = Timex.fromMap(text, attrsMap);\n    return t;\n  } else throw e;\n}","preventionTips":["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."],"tags":["xml-parsing","illegal-argument","timex3","sutime"],"backgroundTag":"invalid-argument-format","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"}