stanfordnlp/CoreNLP · error · IllegalArgumentException

Tag did not start with <

Error message

Tag did not start with <

What it means

XMLUtils.XMLTag's constructor throws IllegalArgumentException when the tag string does not begin with '<'. The constructor assumes well-formed bracketed tags, and this check rejects tokens that clearly are not XML tags.

Solutions

  1. Include the leading '<' in the string passed to XMLTag (e.g. prepend if missing after verifying the fragment is a tag).
  2. Fix the upstream tokenizer to keep the bracket characters.
  3. Validate with tag.startsWith("<") before construction.
  4. Catch IllegalArgumentException and treat the token as non-tag text.

Example fix

// before
new XMLTag("a href=\"x\">"); // throws
// after
String tok = "a href=\"x\">";
if (!tok.startsWith("<")) tok = "<" + tok;
new XMLTag(tok);
Defensive patterns

Strategy: type-guard

Validate before calling

if (tag == null || !tag.startsWith("<")) throw new IllegalArgumentException("not a tag: " + tag);

Type guard

static boolean startsWithTag(String s) {
  return s != null && s.startsWith("<");
}

Try / catch

try {
  new XMLTag(token);
} catch (IllegalArgumentException e) {
  log.warning("malformed tag token: " + token);
}

Prevention

When it happens

Trigger: new XMLTag("name attr=\"x\"") or passing plain text content / a tag body without the opening bracket extracted from a document.

Common situations: Custom XML splitters that strip the '<' during tokenizing; passing escaped or HTML-entity-encoded text to XMLTag.

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


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/6f2ce87aa849e8ac. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/XMLUtils.java:1094

    public Map<String,String> attributes;

    /** Whether this is an ending tag or not. */
    public boolean isEndTag;

    /** Whether this is an empty element expressed as a single empty element tag like {@code <p/>}. */
    public boolean isSingleTag;

    /**
     * Assumes that String contains an XML tag.
     *
     * @param tag String to turn into an XMLTag object
     */
    public XMLTag(String tag) {
      if (tag == null || tag.isEmpty()) {
        throw new NullPointerException("Attempted to parse empty/null tag");
      }
      if (tag.charAt(0) != '<') {
        throw new IllegalArgumentException("Tag did not start with <");
      }
      if (tag.charAt(tag.length() - 1) != '>') {
        throw new IllegalArgumentException("Tag did not end with >");
      }
      text = tag;
      int begin = 1;
      if (tag.charAt(1) == '/') {
        begin = 2;
        isEndTag = true;
      } else {
        isEndTag = false;
      }
      int end = tag.length() - 1;
      if (tag.charAt(tag.length() - 2) == '/') {
        end = tag.length() - 2;
        isSingleTag = true;
      } else {
        isSingleTag = false;

View on GitHub (pinned to 1b7edd19c4)