mybatis/mybatis-3 · warning · UnsupportedOperationException

Remove is not supported, as it has no meaning in the context

Error message

Remove is not supported, as it has no meaning in the context of properties.

What it means

PropertyTokenizer implements Iterator so callers can walk the children of a dotted property path ('a.b.c'). Property paths are read-only descriptions of nested properties; removing a segment has no defined meaning, so Iterator.remove() always throws UnsupportedOperationException. This is an intentional design restriction, not a transient failure.

Source

Thrown at src/main/java/org/apache/ibatis/reflection/property/PropertyTokenizer.java:78

  }

  public String getChildren() {
    return children;
  }

  @Override
  public boolean hasNext() {
    return children != null;
  }

  @Override
  public PropertyTokenizer next() {
    return new PropertyTokenizer(children);
  }

  @Override
  public void remove() {
    throw new UnsupportedOperationException(
        "Remove is not supported, as it has no meaning in the context of properties.");
  }
}

View on GitHub (pinned to 008069adb1)

Solutions

  1. Do not call remove(); build a new property path string instead of mutating the tokenizer
  2. Collect the segments with a while(hasNext()) next() loop and reconstruct the path you want
  3. If generic Iterator code must run, special-case or avoid applying it to PropertyTokenizer

Example fix

// before
Iterator<PropertyTokenizer> it = new PropertyTokenizer(path);
while (it.hasNext()) { it.next(); }
it.remove(); // throws

// after
List<String> segments = new ArrayList<>();
for (PropertyTokenizer t = new PropertyTokenizer(path); t.hasNext(); t = t.next()) {
  segments.add(t.getName());
}
Defensive patterns

Strategy: validation

Validate before calling

// PropertyTokenizer.remove() always throws; simply never call it.
for (PropertyTokenizer t = new PropertyTokenizer(path); t.hasNext(); t = t.next()) {
  segments.add(t.getName()); // read-only traversal
}

Prevention

When it happens

Trigger: Calling remove() on a PropertyTokenizer instance while iterating property paths, e.g. in generic code that treats every Iterator uniformly (frameworks, stream utilities, generic traversal helpers).

Common situations: Utility code that iterates-and-prunes with Iterator.remove(); adapting MyBatis property traversal into a generic collection pipeline; copy-pasted collection-manipulation code applied to a PropertyTokenizer.

Related errors


AI-assisted analysis of mybatis/mybatis-3@008069adb1 (2026-08-14). Data as JSON: /api/errors/6a7fa2c275cc58fd. Report an issue: GitHub.