didi/DoKit · error · IllegalArgumentException
Multiple wildcards present in rule expression " + ruleExpres
Error message
Multiple wildcards present in rule expression " + ruleExpression
What it means
Thrown by MimeMatcher.MimeMatcherRule's constructor when a rule expression contains more than one '*' wildcard. Only a single trailing wildcard (e.g. "image/*") is supported: the constructor strips one trailing '*' into a prefix match, then rejects any remaining '*' in the prefix because prefix matching cannot express interior wildcards.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/network/core/MimeMatcher.java:53
return null;
}
@SuppressLint("BadMethodUse-java.lang.String.length")
private class MimeMatcherRule {
private final boolean mHasWildcard;
private final String mMatchPrefix;
private final T mResultIfMatched;
public MimeMatcherRule(String ruleExpression, T resultIfMatched) {
if (ruleExpression.endsWith("*")) {
mHasWildcard = true;
mMatchPrefix = ruleExpression.substring(0, ruleExpression.length() - 1);
} else {
mHasWildcard = false;
mMatchPrefix = ruleExpression;
}
if (mMatchPrefix.contains("*")) {
throw new IllegalArgumentException("Multiple wildcards present in rule expression " +
ruleExpression);
}
mResultIfMatched = resultIfMatched;
}
public boolean match(String mimeType) {
if (!mimeType.startsWith(mMatchPrefix)) {
return false;
}
return (mHasWildcard || mimeType.length() == mMatchPrefix.length());
}
public T getResultIfMatched() {
return mResultIfMatched;
}
}
}
View on GitHub (pinned to 626827cddb)
Solutions
- Use a single trailing wildcard only: "image/*" instead of "*/*" — for match-everything use an empty prefix with trailing '*', i.e. "*"
- Express interior/suffix patterns as multiple explicit rules or match on substring in your own code instead of MimeMatcher
- Validate the expression at configuration load time and fail fast with a clear config error
Example fix
// before
matcher.addRule("*/*", MATCH_ALL); // second '*' inside prefix -> throws
// after
matcher.addRule("*", MATCH_ALL); // single trailing wildcard, matches everything Defensive patterns
Strategy: validation
Validate before calling
static boolean isValidMimeRule(String expr) {
if (expr == null) return false;
String prefix = expr.endsWith("*") ? expr.substring(0, expr.length() - 1) : expr;
return prefix.indexOf('*') == -1;
} Prevention
- Use only a single trailing wildcard ('image/*', '*')
- Do not copy Accept-header patterns like '*/*' or '*+json' into MimeMatcher rules
When it happens
Trigger: Constructing a rule with expression "*/*", "image/*;q=*", "application/*+json*", or any string where '*' appears anywhere except the final character. The check runs at rule-creation time, before any match() call.
Common situations: Registering MIME rules for the network/image inspector with patterns borrowed from Accept headers (where "*/*" is idiomatic) or glob habits from other libraries; trying to express suffix patterns like "*+json".
Related errors
- Expected alternating header names and values
- Unexpected header: " + name + ": " + value
- Unexpected char %#04x at %d in header name: %s
- Unexpected char %#04x at %d in %s value: %s
- maxStoredHeapDumps must be at least 1
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/61699324c19d9a6b.
Report an issue: GitHub.