stanfordnlp/CoreNLP · error · IllegalArgumentException

Tag did not end with >

Error message

Tag did not end with >

What it means

XMLUtils.XMLTag's constructor throws IllegalArgumentException when the tag string does not end with '>'. Along with the '<' check, this guarantees the constructor only receives bracket-delimited tag text it can parse for name/attributes.

Solutions

  1. Ensure the complete '<' ... '>' token is passed; buffer input until the closing '>' is available.
  2. Validate with tag.endsWith(">") before construction.
  3. Fix upstream splitting logic to split on tag boundaries, not line breaks.
  4. Catch IllegalArgumentException and reassemble/skip the malformed fragment.

Example fix

// before
for (String line : xml.split("\n")) new XMLTag(line.trim()); // may cut tags
// after
Matcher m = Pattern.compile("<[^>]*>").matcher(xml);
while (m.find()) new XMLTag(m.group());
Defensive patterns

Strategy: type-guard

Validate before calling

if (tag == null || !tag.endsWith(">")) throw new IllegalArgumentException("truncated tag: " + tag);

Type guard

static boolean isCompleteTag(String s) {
  return s != null && s.length() >= 2 && s.endsWith(">") && s.startsWith("<");
}

Try / catch

try {
  new XMLTag(token);
} catch (IllegalArgumentException e) {
  buffer.append(token); // wait for the rest of the tag
}

Prevention

When it happens

Trigger: new XMLTag("<a href=\"x\"") where a trailing '>' was lost to truncation or a line-based splitter cut the tag mid-way.

Common situations: Reading XML wrapped across lines and splitting on newline, cutting tags in half; truncated files or streamed input buffered mid-tag.

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/dd9eb841bad6c5fc. Report an issue: GitHub.

Appendix: source

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

    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;
      }
      tag = tag.substring(begin, end);
      attributes = Generics.newHashMap();

View on GitHub (pinned to 1b7edd19c4)